我在桌面上的下方有这个按钮 - 当用户单击它时,它将把他们带到下面的某个部分。但是我怎样才能更改按钮的链接呢?假设用户使用的是 Android 手机,此按钮的链接将更改为 Google Play 商店,而在 IOS 上它将更改为苹果商店?
<div class="get_the_app">
<a href="#get_app">get the app</a>
</div>
最佳答案
试试这个很简单
<div class="get_the_app">
<a id="store" href="#get_app">get the app</a>
</div>
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");
}
我也包含了windows store
关于javascript - 动态更改 CTA 按钮链接(在 iOS 或 Android 或网页上)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39760019/