Determining the screen size in JavaScriptQuestion: How do I get the screen size on the client machine?
Answer:
To determine the screen size on the client machine, use the properties
If you need a reduced value (subtracting the screen portion occupied by toolbars etc.),
use
Historical note: For Netscape Navigator 3 (with Java enabled), you could use a Java call to get the screen width and height (see the example below).
The following code sets the variables
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:
|
Copyright © 1999-2011, JavaScripter.net.