Click to See Complete Forum and Search --> : Get Current Window W+H dimensions


Beriah
07-08-2003, 12:34 AM
Hello,

I want to know how to get the Width+Height of a browser window onload.

im currently trying:
var wiw = window.innerWidth
var dw = document.clientWidth

but unless it is placed within a window that is created wtih specific width/heights stated, i cant get anything but an "undefined" error.

Does anyone have any suggestions?

Regards
Beriah

Fang
07-08-2003, 05:56 AM
It depends on your browser and when you poll the window.
Call this function AFTER the window has loaded:

var Ypos, Xpos, theWidth, theHeight;
function WindowSize() {
// Scroll offset:
if (window.pageYOffset)
Ypos=window.pageYOffset;
else if (document.documentElement && document.documentElement.scrollTop)
Ypos=document.documentElement.scrollTop;
else if (document.body)
Ypos=document.body.scrollTop;

if (window.pageXOffset)
Xpos=window.pageXOffset;
else if (document.documentElement && document.documentElement.scrollLeft)
Xpos=document.documentElement.scrollLeft;
else if (document.body)
Xpos=document.body.scrollLeft;
// Window dimensions:
if (window.innerWidth)
theWidth=window.innerWidth;
else if (document.documentElement && document.documentElement.clientWidth)
theWidth=document.documentElement.clientWidth;
else if (document.body)
theWidth=document.body.clientWidth;

if (window.innerHeight)
theHeight=window.innerHeight;
else if (document.documentElement && document.documentElement.clientHeight)
theHeight=document.documentElement.clientHeight;
else if (document.body)
theHeight=document.body.clientHeight;
}