Categories:

Site Search:

Find me at:


Share/Save/Bookmark

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 ,,, ?

JayZ said on 27.10.2008. 00:36

Screen resolution is given in pixels per meter, or similar. screen.width does not give screen resolutions.

Andy said on 27.10.2008. 19:44

JayZ - screen or display resolution is the agreed terminology to refer to the pixel dimensions of a screen. You could argue that this is not entirely accurate, but generally people refer to PPI/DPI using different terminology - that's just the way the language has evolved. Don't blame me ;)

mscro said on 18.11.2008. 21:19

This work only with main window :-( i have 2 monitors, one is 1440x900 and second 1024x768 using script and browser on second monitor(1024x768) i get resultat 1440x900 do you have idea how i can solve this problem?? tnx

anjali said on 20.11.2008. 12:35

pl. tell me argent how i can create fixable website window in any screen resolution

thx

puput said on 17.12.2008. 12:32

thx for ur info

maduranga001 said on 19.12.2008. 12:11

I did it like this.Helped me a lot.tnx
function getClientResolution() {
//document.write();


var res = $get("");
res.value = screen.width + 'x' + screen.height;
//alert(res);
}

Abduls said on 01.03.2009. 09:23

Good very helpfull

SicleRose said on 18.03.2009. 21:39

this might be helpfull, this code gets the resolution with java then makes php variables with it:


var reswidth= (screen.width)
var resheight= (screen.height)



just make a file called: getres.php, and you can include it in any php file with:
require("getres.php");

$reswidth; is the width only,
$resheight; is the height only,
$res; is width x height.

hope it helped.

Jonathan said on 16.05.2009. 03:43

Hey, what is when I wnat only the screen resolutio:
if weidth:0-800 and height 0-600

if wiedth 801-1024 and height 601-768


how do I code this..like to ifs

GR said on 27.05.2009. 02:07

Mr. Langton
Thank You very much.
We really appreciate your work.

arvind said on 02.06.2009. 20:11

Great info
Thanks

pelle said on 31.08.2009. 09:27

Cant believe how simple this was. Theres more to the web than php..=)

palPalani said on 27.10.2009. 11:01

excellent solution!

Harry said on 19.11.2009. 16:14

Thanks Andy,

I am thinking of re-designing some of my URLs and may incorporate some of this to offer my users a better experience.

Harry

Steve said on 05.12.2009. 14:17

What would the argument be for else if you just wanted the browser to stay on the current page?

Stevo said on 26.01.2010. 07:41

Awesome!
Thanks so much,,,,,

krishna said on 26.01.2010. 07:43

Thanks a lot..

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

:

:

:


1 + 1 =

Articles RSS feed

Page last (manually) updated: December 23, 2009.