Search code examples
javascriptiphonemobileipadmobile-safari

how do i disable a certain javascript on iphone/ipad or other mobile devices?


I got this for IE browsers,

var IE = /*@cc_on!@*/false;

if (IE) {
    // IE.
} else {
    // Others.
}

but how would i do the same for iphone/ipad/mobiledevices? (do not want to redirect to another page on any mobile devices)


Solution

  • You may want to check the user agent string as follows:

    var userAgent = navigator.userAgent;
    
    if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)) {
       // iPad or iPhone
    }
    else {
       // Anything else
    }