MattsBits
MattsBits - Brunel District

MattsBits

MattsBits RSS Feed - Subscribe Now!

26/04/2009 : Get The Width Of The Browser Window

Categories : | JavaScript | Views : 310 | Email Link Print

Sometimes it is useful to obtain the dimensions of the users browser window. The following JavaScript code can be used to obtain the height and width :

<script type="text/javascript">
<!--

  var v_width;
  var v_height;
  
  // Standards compliant browsers (mozilla/netscape/opera/IE7)
  // use window.innerWidth and window.innerHeight
  
  if (typeof window.innerWidth != 'undefined')
  {
    v_width = window.innerWidth,
    v_height = window.innerHeight
  } else if (typeof document.documentElement != 'undefined'
          && typeof document.documentElement.clientWidth != 'undefined'
          && document.documentElement.clientWidth != 0) {
    // IE6 in standards compliant mode
    // (i.e. with a valid doctype)
    v_width = document.documentElement.clientWidth,
    v_height = document.documentElement.clientHeight
  } else {
    // older versions of IE
    v_width = document.getElementsByTagName('body')[0].clientWidth,
    v_height = document.getElementsByTagName('body')[0].clientHeight
  }
  document.write('<p>Viewport size : ' + 
                  v_width + 'x' + 
                  v_height + '</p>');

//-->
</script>

Technorati Tags : | javascript |

Author : Matt Hawkins  Last Edited By : Matt Hawkins  Permalink : Get The Width Of The Browser Window
 
 
 
PHP Powered  MySQL Powered  Valid XHTML 1.0  Valid CSS  Firefox - Take Back The Web  EUKHost - Recommended Webhosting Solutions

MattHawkins CMS v2.0 - Copyright 2009-2010