Manga
Manga

Reputation: 111

jQuery - Get Screen Size Width

Trying to grab the screen size and add an if / else query, but for some reason I can't get it to work

What I'm looking for is if the screen width is larger / equal 480px, the following should be outputted:

{$pPage = $cWidth}

Else this:

{$pPage = 1}

This is what I have so far:

<script type="text/javascript">
(function($) {
    $(document).ready(function() {    
        {$pPage = $cWidth}    
})(jQuery);
</script>

Anybody out there with advice how to add the the query in reference to the screen.width, so that it also works?

Upvotes: 11

Views: 49057

Answers (1)

user2232273
user2232273

Reputation: 4974

try this:

using jquery:

if ($(window).width() < 1280) {
   alert('Less than 1280');
}
else {
   alert('More than 1280');
}

OR

using javascript:

var screensize = document.documentElement.clientWidth;
if (screensize  < 1280) {
   alert('Less than 1280');
}
else {
   alert('More than 1280');
}

Upvotes: 36

Related Questions