Screen Size
Question: How do I get the screen size on the client machine?
Answer:
To determine the screen size on the client machine, use the properties
screen.width and
screen.height
supported by version 4 of both major browsers.
If your user has Netscape Navigator 3 and enables Java,
you use a Java call to get the screen width and height (see the example below).
The following code sets the variables
screenW and
screenH to the actual width and height of the screen,
and outputs the width and height values.
If the user has an old browser, then
screenW and
screenH are set to 640 and 480, respectively.
var screenW = 640, screenH = 480;
if (parseInt(navigator.appVersion)>3) {
screenW = screen.width;
screenH = screen.height;
}
else if (navigator.appName == "Netscape"
&& parseInt(navigator.appVersion)==3
&& navigator.javaEnabled()
)
{
var jToolkit = java.awt.Toolkit.getDefaultToolkit();
var jScreenSize = jToolkit.getScreenSize();
screenW = jScreenSize.width;
screenH = jScreenSize.height;
}
document.write(
"Screen width = "+screenW+"<br>"
+"Screen height = "+screenH
)
In your browser, this code produces the following output:
JavaScripter.net.
Copyright
© 1999-2006, Alexei Kourbatov