D
dhtml
4.9 How do I find the size of the window/browser canvas area?
The answer is completely wrong and the example code is not cross
browser.
innerWidth is not the same as documentElement.clientWidth. innerWidth
includes scrollbar, clientWidth doesn't. This is a mistake I see all
over the web and I bet there are people who got that from
c.l.javascript FAQ.
The correct answer is:
It is not possible to accurately determine the width of the canvas
area, cross browser. There are various non-standard properties that
may provide some information about the viewport, but they differ
between browsers, versions, and rendering modes, so it is difficult to
accurately determine if the value can be relied upon.
| Where supported in modern browsers:
|
| var winWidth = document.documentElement.clientWidth;
| var winHeight = document.documentElement.clientHeight;
This won't work reliably. In Opera 9, documentElement.clientHeight
won't return the window height. Instead, it will return the
clientHeight of the documentElement (the HTML HTMLElement). Opera
seems to return the viewport height (no scrollbars) for
document.body.clientHeight, for no apparent reason. I would call this
a bug.
The buggy code should be removed from the FAQ.
Garrett
The answer is completely wrong and the example code is not cross
browser.
innerWidth is not the same as documentElement.clientWidth. innerWidth
includes scrollbar, clientWidth doesn't. This is a mistake I see all
over the web and I bet there are people who got that from
c.l.javascript FAQ.
The correct answer is:
It is not possible to accurately determine the width of the canvas
area, cross browser. There are various non-standard properties that
may provide some information about the viewport, but they differ
between browsers, versions, and rendering modes, so it is difficult to
accurately determine if the value can be relied upon.
| Where supported in modern browsers:
|
| var winWidth = document.documentElement.clientWidth;
| var winHeight = document.documentElement.clientHeight;
This won't work reliably. In Opera 9, documentElement.clientHeight
won't return the window height. Instead, it will return the
clientHeight of the documentElement (the HTML HTMLElement). Opera
seems to return the viewport height (no scrollbars) for
document.body.clientHeight, for no apparent reason. I would call this
a bug.
The buggy code should be removed from the FAQ.
Garrett