How can I get browser width in pixels using JavaScript?

I want to set the width of the <iframe> based on the width and height of the browser.

Is it possible to increase browser width in pixels using JavaScript?

+4
source share
3 answers

Try using:

 $(window).width(); 
+7
source

If you do not want to use jQuery to determine the actual size of the browser window, use the following properties:

in Internet Explorer (quirks mode):

 document.body.offsetWidth 

in Internet Explorer <9 (standards mode):

 document.documentElement.offsetWidth 

in most other browsers:

 window.innerWidth 
+4
source

you can try this.

  var objlast = document.getElementById('lastdiv'); if (objlast.offsetParent) { do { curleftLast += objlast.offsetLeft; curtopLast += objlast.offsetTop; } while (objlast = objlast.offsetParent); } document.getElementById('iframe').style.height = curtopLast+"px"; 

this will work as well, and the lastdiv will be the endpoint of your window where you want to get the window height from.

Thanks.

0
source

All Articles