我想创建一个简单的按钮,根据他们正在运行的移动操作系统(ios、android 或 wp8)将移动用户重定向到适当的应用商店链接——或者如果不是在移动设备上,则提供发送包含以下内容的电子邮件适当的链接...有什么想法吗?
最佳答案
嗯...这实际上非常简单。首先,您必须通过用户代理字符串检测用户当前使用的设备。然后使用 jQuery 简单地正确设置 anchor 元素的 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");
}
关于javascript - 一个按钮——3个应用商店——如何将用户重定向到合适的应用商店?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25210456/