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>