-2

I want to make an HTML and depending on the device from which you access a web go to iTunes or Google Play .

For example:

midominio.com/hola.html

If I access from web go to midominio.com If I access from iphone, ipad go to iTunes google maps ( APP ) If I access from Android go toGoogle Play google maps ( APP )

Thank you

  • 1
    check the `userAgent` to know what sort of device you are and then show the appropriate link :). See [iOS detection](http://stackoverflow.com/questions/9038625/detect-if-device-is-ios) and [Android detection](http://stackoverflow.com/questions/6031412/detect-android-phone-via-javascript-jquery) – Yoplaboom Feb 18 '16 at 13:18

2 Answers2

1

First, detect on what sort of device you are

var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1;
var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;

and then play with your link visibility

if(isAndroid) {
    document.getElementById('android').style.display = 'initial';
  document.getElementById('ios').style.display = 'none';
}

if(isIOS) {
    document.getElementById('android').style.display = 'none';
  document.getElementById('ios').style.display = 'initial';
}

if(!isAndroid && !isIOS) {
    document.getElementById('android').style.display = 'initial';
  document.getElementById('ios').style.display = 'initial';
}

Have a look to this jsFiddle

Yoplaboom
  • 554
  • 3
  • 13
0

Hi Can get details by navigator.userAgent Check the code below.

<div id="demo"></div>

<script>
var txt = "";
txt += "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt += "<p>Browser Name: " + navigator.appName + "</p>";
txt += "<p>Browser Version: " + navigator.appVersion + "</p>";
txt += "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt += "<p>Browser Language: " + navigator.language + "</p>";
txt += "<p>Browser Online: " + navigator.onLine + "</p>";
txt += "<p>Platform: " + navigator.platform + "</p>";
txt += "<p>User-agent header: " + navigator.userAgent + "</p>";

document.getElementById("demo").innerHTML = txt;
</script>

output for my browser was

Browser CodeName: Mozilla

Browser Name: Netscape

Browser Version: 5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36

Cookies Enabled: true

Browser Language: en-US

Browser Online: true

Platform: Win32

User-agent header: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36

Hope this will help you...

Anil Kumar Ram
  • 1,211
  • 11
  • 14