8

Is there a way to get the a users screen size/resolutions using javascript? I figured you probably can't use PHP to do this as it's server-side, but as javascript is client-side I thought it may be an option.

2 Answers 2

10

Yes, you can use the following to print out the resolution for example:

<script type="text/javascript">
document.write(screen.width+'x'+screen.height);
</script>

Might not work in older browsers, but will in most recent ones.

More info here:

http://www.javascriptkit.com/howto/newtech3.shtml

Sign up to request clarification or add additional context in comments.

1 Comment

On a related note: see stackoverflow.com/questions/6648155/… if you need to find the usable space in the browser window.
1

Yes i have used the following code and it works well.

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
)

Courtesy: http://www.javascripter.net/faq/screensi.htm

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.