Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 414
Manga Avatar asked Jan 25 '14 19:01

Manga


1 Answers

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');
}
like image 76
user2232273 Avatar answered Oct 25 '22 23:10

user2232273