Alistair
Alistair

Reputation: 491

Disable .js file for specific media query?

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>

Upvotes: 1

Views: 297

Answers (1)

ovi
ovi

Reputation: 576

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>

Upvotes: 1

Related Questions