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
Niyaz PK said on 16.01.2008. 06:19
Thanks for the info
I used this code in my website.
Recent Comments:
Page last (manually) updated: May 01, 2007.
Questions, comments, insults or praise? Have your say: