Sunday, November 29, 2009

Get screen resolution in JavaScript

How to get screen resolution in JavaScript?


 You can get your screen resolution/ screen width and height using following JavaScript. It shows you the screen resolution of your computer screen in pixel. When designing web application for different screen sizes this may be very useful.


HTML and JavaScript Code
<head>
<title>Screen Resolution</title>
<script type="text/javascript" language="javascript">
function getScreenResolution(){
                var width=screen.width;
                var height = screen.height;
                document.getElementById("txt_screen_width").value=width;
                document.getElementById("txt_screen_height").value=height;
}
</script>
</head>
<body onLoad="javascript:getScreenResolution();">
<form id="form_screen_resolution" name="form_screen_resolution" method="post" action="">
  <table width="200" border="0">
    <tr>
      <td colspan="2" align="center"><strong>Screen resolution </strong></td>
    </tr>
    <tr>
      <td>Width</td>
      <td valign="middle">
        <input name="txt_screen_width" type="text" id="txt_screen_width" size="5" />
        px      </td>
    </tr>
    <tr>
      <td>Height</td>
      <td valign="middle">
        <input name="txt_screen_height" type="text" id="txt_screen_height" size="5" />
        px      </td>
    </tr>
  </table>
</form>
</body>
</html>

3 comments:

jaymar said...

Thanks for sharing. The rewards in joy, appreciation are probably incalculable.

www.n8fan.net

andrea chiu said...


There are times that we encounter fear and disappointments in life yet we still manage to stand up straight and face it rather than being silent. That is a very good example of being a brave and strong person. Well, I would like to thank you for sharing a very good article it is very much appreciated, good job! You can visit my site too if you want. Have a great day.Enjoy!

triciajoy.com

www.triciajoy.com

Cindy Dy said...

Very interesting story. I didn't find it boring to read. In fact, I really had a lot of fun reading your post. Thanks.

Bob
www.gofastek.com