简体   繁体   中英

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)

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
}

That should be a bit of a problem because every app makes its own Header. My apache server gets this as Browser: [APPNAME]/1.0_CFNetwork/459_Darwin/10.3.0

You could search for Darwin, but I don't know if this is waterproof.

A JS-Snippet should look like that:

if (navigator.userAgent.indexOf("Firefox") != -1)
{
   document.write('You're using Mozilla Firefox');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM