disable_js_on_mobile.js
· 332 B · JavaScript
Неформатований
// method 1
function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
if (!isMobile()) {
//place script you don't want to run on mobile here
}
// method 2
if (window.matchMedia('(min-width: 768px)').matches) {
//place script you don't want to run on mobile here
}
| 1 | // method 1 |
| 2 | function isMobile() { |
| 3 | return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); |
| 4 | } |
| 5 | |
| 6 | if (!isMobile()) { |
| 7 | //place script you don't want to run on mobile here |
| 8 | |
| 9 | } |
| 10 | |
| 11 | |
| 12 | // method 2 |
| 13 | if (window.matchMedia('(min-width: 768px)').matches) { |
| 14 | //place script you don't want to run on mobile here |
| 15 | } |