Entry
How can I find the screen size/resolution?
How can I find the screen size/resolution?
How can I find the color depth?
How can I find the window size?
Jun 9th, 2003 02:26
Michel Plungjan, Klaus Bolwin, Phil S., Marc-André Dumas, Martin Honnen,
Client side JavaScript 1.2 (around in NN4+ and IE4+) introduced the
window.screen
object with properties
window.screen.width
window.screen.height
window.screen.availWidth
window.screen.availHeight
window.screen.colorDepth
window.screen.pixelDepth (I think that is NN only)
So to check the absolute size of the screen use
window.screen.width/height
but if you want to size a window consider
window.screen.availWidth/availHeight
as that values take account of the taskbar or similar permanent screen
objects.
For NN3 there is the possibility to call into java to find the screen
dimensions:
java.awt.Toolkit.getDefaultToolkit().getScreenSize().width
java.awt.Toolkit.getDefaultToolkit().getScreenSize().height
If you want the window size, you can use:
With IE4:
document.body.clientWidth
document.body.clientHeight
or better you should use:
document.documentElement.offsetWidth
document.documentElement.offsetHeight
since this is also available in the head of the document,
body.clientWidth is available after the declaration of the body-element
only.
However in IE6 they are not the same values. clientWidth/Height is
smaller. In Mozilla the document.documentElement.offsetWidth is NOT
available until after load
With NN4:
self.innerWidth
self.innerHeight
You can also use for the aviable screen size:
screen.availWidth
screen.availHeight