Categories:

Site Search:


Get Monitor Screen Resolution with Javascript

Find out and display a user's screen resolution with javascript

In javascript, the screen.width and screen.height properties contain the size a visitor's monitor is set to. Bear in mind that the size the monitor is set to is not the same as the size of the browser window a visitor is using - windows can of course be set to different sizes. To find out this information you need to check the height and width of the viewport (different methods for different browsers, unfortunately).

Your current screen resolution (if you have javascript enabled) is

To display a visitor's screen resolution, simple include the following code in your page:

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

Screen resolution redirect

Once you know what a visitor's screen resolution is, you can redirect them to a particular page. Admittedly, you'd be better off with a page that worked at any screen resolution, but anyhow ;)

The script below will redirect users based on whether or not they have a monitor resolution of 800x600 or below:

<script type="text/javascript">
if ((screen.width<=800) && (screen.height<=600)) {
 window.location.replace('http://example.com/800-600-or-less');
}
else {
   window.location.replace('http://example.com/greater-than-800-600');
}
</script>

Related Tools

If you want to actually test different screen resolutions, use the Screen Resolution Checker

28.03.2007. 00:15

good said on 30.04.2007. 09:32

good one

Niyaz PK said on 16.01.2008. 06:19

Thanks for the info
I used this code in my website.

hacker said on 25.01.2008. 11:14

Thanks boddy ,,, ?

Questions, comments, insults or praise? Have your say:

:

:

:


3 + 8 =

Page last (manually) updated: May 01, 2007.