我想创建一个简单的按钮,根据移动用户正在运行的移动操作系统(ios,android或wp8)将移动用户重定向到相应的应用商店链接-或如果不在移动设备上,则建议发送包含相应链接的电子邮件...有任何想法吗?
好吧...这实际上非常简单。首先,您必须通过用户代理字符串检测用户当前正在使用的设备。然后使用jQuery简单地href
正确设置锚元素的属性。以下代码进行了说明。
var operatingSystem, userAgentString = navigator.userAgent;
var link = $("#store");
if (userAgentString.indexOf("iPhone") > -1 || userAgentString.indexOf("iPod") > -1 || userAgentString.indexOf("iPad") > -1) {
operatingSystem = "iOS";
link.attr("href", "http://store.apple.com/us/browse/app");
} else if (/Android/.test(userAgentString)) {
operatingSystem = "Android";
link.attr("href", "https://play.google.com/store/apps?hl=en");
} else if (/Windows Phone/.test(userAgentString)) {
operatingSystem = "Windows Phone";
link.attr("href", "http://www.windowsphone.com/en-us/store");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句