Using jQuery To Get Size of Viewport

Volomike picture Volomike · Jun 15, 2010 · Viewed 285.7k times · Source

How do I use jQuery to determine the size of the browser viewport, and to redetect this if the page is resized? I need to make an IFRAME size into this space (coming in a little on each margin).

For those who don't know, the browser viewport is not the size of the document/page. It is the visible size of your window before the scroll.

Answer

SimaWB picture SimaWB · Jun 15, 2010

To get the width and height of the viewport:

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

resize event of the page:

$(window).resize(function() {

});