-3

How do I turn Javascript off when my page is viewed on mobiles?

I need a sort of media query that will disable all javascript on a page when viewed on a specific device.

So far I have this but do not know how to actually disable all javascript

if(screen.width < 480) { 
    // do any 480 width stuff here, or simply do nothing
    return;
} else {
    // do all your cool stuff here for larger screens
}

Thanks

5kud
  • 327
  • 2
  • 6
  • 19
  • 1
    It is expected that you at least attempt to code this for yourself. Stack Overflow is not a code writing service. I would suggest that you do some additional research, either via Google or by searching SO, make an attempt and. if you still have trouble, come back with **your code** and explain what you have tried and why it did not work. – Paulie_D Feb 10 '16 at 11:14
  • Your question is not clear at all. – Torsten Barthel Feb 10 '16 at 11:16
  • 1
    I have researched and can't find a result, meaning I came here as a last resort. For advice on how to tackle this. – 5kud Feb 10 '16 at 11:21
  • Possible duplicate of [Disable javascript on mobile websites](http://stackoverflow.com/questions/18005658/disable-javascript-on-mobile-websites) – twernt Feb 10 '16 at 14:27

2 Answers2

1

You could use matchMedia.js (found at https://github.com/paulirish/matchMedia.js) and check if the screen is below a certain size.

Eg. if (matchMedia('(max-width: 480px)')) { // Run Code Here }

0

You can check the

navigator.userAgent

property with Javascript. This will show the used browser and you can determine if its mobile or not.

Documentation: userAgent Docs

You can do it also width the viewport width of your users browser in pure Javascript:

var w = document.documentElement.clientWidth;
Torsten Barthel
  • 3,059
  • 1
  • 26
  • 22