Posted By

vaughanj on 10/23/12


Tagged


Versions (?)

Browser window dimensions


 / Published in: JavaScript
 

Get the browser width and height. Useful for testing responsive layouts. Out the data feedback into the following HTML:

  1. function report() { document.getElementsByTagName('output')[0].innerHTML = 'screen.width:'+screen.width+'<br>screen.height:'+screen.height+'<br>window.innerWidth:'+window.innerWidth+'<br>window.innerHeight:'+window.innerHeight+'<br>window.outerWidth:'+window.outerWidth+'<br>window.outerHeight:'+window.outerHeight+'<br>document.documentElement.<br> clientWidth:'+document.documentElement.clientWidth+'<br>document.documentElement.<br> clientHeight:'+document.documentElement.clientHeight+'<br>window.devicePixelRatio:'+window.devicePixelRatio; }
  2. window.addEventListener('load', report, false);
  3. window.addEventListener('resize', report, false);
  4. window.addEventListener('orientationchange', report, false);
  5. window.addEventListener('deviceorientation', report, false);
  6. window.addEventListener('MozOrientation', report, false);

Report this snippet  

You need to login to post a comment.