Getting the page and viewport dimensions using jQuery

Tue, Jun 8, 2010

Javascript, Programming, Snippets

thats why i Love jquery, cause everything is so simple…

To get the width and height of the whole page (document), use:

var pageWidth = $(document).width();
var pageHeight = $(document).height();

To get the width and height of the viewport (window), use:

var viewportWidth = $(window).width();
var viewportHeight = $(window).height();

Opera though has a different approach. with Opera 9.5 $(window).height() returns the document height (more info here)
you can get around this by using

var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
Share

Related posts:

  1. get CKEditor data with Jquery – no plugin required If you are using the CKeditor also with JQuery (not...
  2. JQuery wildcard selectors JQuery wildcard selectors on select boxes, how to reset all...
  3. Custom info windows with jQuery and Google Maps Ben Nolan has a writeup on a new feature in...
  4. 25 jQuery image galleries and slideshow plugins For some sites, image galleries are an absolute must. Portfolios...
  5. Qooxdoo 0.8.2 Featuring A Cross-Browser “Inspector” Tool Qooxdoo 0.8.2 has just been released with some cool new...

, , ,

This post was written by:

- who has written 193 posts on ropox.net.

Software Engineer and Web Developer, keen on new technologies and has passion for web engineering.... Internet is my job and i love it...!!! Founded Baldpixel (baldpixel.com) on 2008 which is specialized on enginnering custom web projects while cooperating with top advertising agencies on the net.

Contact the author

Leave a Reply