4

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

Is it possible to get the browser's width in pixels using JavaScript?

3 Answers 3

7

Try using :

$(window).width();
0
4

If you don't 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
0

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 also work, and lastdiv would be the endpoint of your window from where you want to fetch window height.

Thanks.

Not the answer you're looking for? Browse other questions tagged or ask your own question.