Detect the mobile operating system and redirect to a specific page

-1

Good afternoon guys, okay? I would like someone to guide me in one thing, I'm trying to implement a website, a button where to depend on the operating system, it redirects to a website. Ex: If the person's phone is Android, I put it to redirect to the playstore, if it's an Iphone, I put it to redirect to the AppStore, can someone help me please.

    
asked by anonymous 28.11.2018 / 20:33

1 answer

1

use this function

function descobreOs() {
  var userAgent = navigator.userAgent || navigator.vendor || window.opera;


    if (/windows phone/i.test(userAgent)) {
        return "Windows Phone";
    }

    if (/android/i.test(userAgent)) {
        return "Android";
    }


    if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
        return "iOS";
    }

    return "n_sei";
}

So just to debug you do:

alert(descobreOs());
    
28.11.2018 / 21:02