How to disable specific 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 to do the same for iphone / ipad / mobiledevices? (don't want to redirect to another page on any mobile devices)

+4
source share
2 answers

You can 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 } 
+8
source

This should be a problem, because each application creates its own header. My Apache server receives this as a browser: [APPNAME] /1.0_CFNetwork/459_Darwin/10.3.0

You can search for Darwin, but I do not know if it is waterproof.

JS-Snippet should look like this:

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

Source: https://habr.com/ru/post/1308575/


All Articles