Monday, February 18, 2008

how to determine window size in javascript

Use this snippet to determine the size of an open window. Can be used in many different situations, e.g., for setting the size of a div.
<script type="text/javascript">

if (window.innerWidth)
  theWidth=window.innerWidth;
else if (document.documentElement && document.documentElement.clientWidth)
  theWidth=document.documentElement.clientWidth;
else if (document.body)
  theWidth=document.body.clientWidth;

if (window.innerHeight)
  theHeight=window.innerHeight;
else if (document.documentElement && document.documentElement.clientHeight)
  theHeight=document.documentElement.clientHeight;
else if (document.body)
  theHeight=document.body.clientHeight;
//test
//alert(theWidth+'x'+theHeight);

</script>

 
Blogger Template Layout Design by [ METAMUSE ] : Code Name Gadget 1.1 Power By freecode-frecode.blogger.com & blogger.com Programming Blogs - BlogCatalog Blog Directory