Click here to Skip to main content
Click here to Skip to main content

Finding resolution of the system with javascript

, 7 Dec 2006
Rate this:
Please Sign up or sign in to vote.
tutorial to detect the resolution of the system and load appropriate page

Sample Image - top.jpg

Introduction

   Many times while designing websites we face the problem for selecting the resolution for the site. Here is a small tutorial on how we can solve this problem.

  In this tutorial I have used javascript to find the resolution of the client system and depending upon it we can load the page designed for the appropriate system resolution

Code

   Here javascript is used to find the current resolution of the the client system which prints the value on the screen .

<script>

document.write ("Your screen resolution is : ");

document.write (screen.width); //prints the width of screen in pixels

  document.write ( " by ");

document.write (screen.height); //prints the height of screen in pixels

</script>

It shows the resolution of the screen as shown above.

Now ,the required page can be loaded by using simple if else statement by comparing the current screen resolution to the desired one. The command for loading a page through javascript is

 

location.href =  'index86.htm';  //given in the javascript file inside the if statement

 

The Rest of the Story

The rest is fairly simple. Just extract the files to a folder and open index.htm file .It will detect the resolution and automatically load the page correct for thsat resolution.I hope that this may help some of the beginners  in designing .

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Shailendra Sason
Software Developer
India India
No Biography provided

Comments and Discussions

 
QuestionNope. This ain't going to work for new trends.. Check this! Pinmemberlakshmignarayanan20-May-12 20:22 
GeneralNot sure this is such a good idea PinmemberMihai Nita22-Sep-06 11:14 
GeneralRe: Not sure this is such a good idea PinmemberGarry Shutler23-Sep-06 23:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 7 Dec 2006
Article Copyright 2006 by Shailendra Sason
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid