1

I want to disable my .js file when a browser window is less than 1000px but I also want to disable it for specific devices / media queries.

So for example, I want to make sure it doesn't load on iPad.

I have got the 1000px part sorted but I am not sure how to also implement the media query?

<script>
$(function() {
var windowWidth = $(window).width();
if(windowWidth > 1000){
    skrollr.init({
        forceHeight: false
    });
}});
</script>
Sébastien
  • 10,675
  • 11
  • 47
  • 67
Alistair
  • 158
  • 3
  • 15
  • It is AFAIK not possible. Use http://mobiledetect.net ( my choice ) if you can use PHP! – loveNoHate Sep 15 '14 at 12:09
  • This should help with your problem: http://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-handheld-device-in-jquery – bencripps Sep 15 '14 at 12:09
  • Oh, I got the question the other way around. JS in media-query. Look here: http://davidwalsh.name/add-rules-stylesheets. – loveNoHate Sep 15 '14 at 12:12

1 Answers1

1

You need to detect the userAgent, as seen here : What is the best way to detect a mobile device in jQuery?

In your code :

<script>
        $(function() {
             var windowWidth = $(window).width();
          if(windowWidth > 1000 && !(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))){
           skrollr.init({
           forceHeight: false
          });
          }});
    </script>
Community
  • 1
  • 1
ovi
  • 526
  • 3
  • 17