rory-h rory-h - 1 year ago 64
Android Question

Dynamically change CTA button links (when on iOS or Android or web page)?

I have this button below which on desktop - when the user clicks it, it will bring them to a certain section as below. But how can I change the link to of the button so let's say - user is using an android phone the link of this button will change to google play store and when on IOS it will change to apple store?

<div class="get_the_app">
<a href="#get_app">get the app</a>

Answer Source

It is pretty easy try this

<div class="get_the_app">
           <a id="store" href="#get_app">get the app</a>

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", "");
} else if (/Android/.test(userAgentString)) {
    operatingSystem = "Android";
    link.attr("href", "");
} else if (/Windows Phone/.test(userAgentString)) {
    operatingSystem = "Windows Phone";
    link.attr("href", "");

I have included windows store as well

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download