Detect the mobile operating system and redirect to a specific page

Asked

Viewed 389 times

-1

Good afternoon guys, all right? , I would like someone to guide me on something, I’m trying to implement on a website, a button where depending 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 is Iphone, I put to redirect to the Appstore, someone can help me please.

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";
}

then only for debug you do:

alert(descobreOs());
  • 1

    It worked!! Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.