Duminda Chamara

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
<title>Screen Resolution</title>
<script type="text/javascript" language="javascript">
function getScreenResolution(){
                var width=screen.width;
                var height = screen.height;
<body onLoad="javascript:getScreenResolution();">
<form id="form_screen_resolution" name="form_screen_resolution" method="post" action="">
  <table width="200" border="0">
      <td colspan="2" align="center"><strong>Screen resolution </strong></td>
      <td valign="middle">
        <input name="txt_screen_width" type="text" id="txt_screen_width" size="5" />
        px      </td>
      <td valign="middle">
        <input name="txt_screen_height" type="text" id="txt_screen_height" size="5" />
        px      </td>


jaymar said...

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


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!



Unknown 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.