Skip to content

Instantly share code, notes, and snippets.

@THEtheChad
Created January 18, 2012 20:46
Show Gist options
  • Save THEtheChad/1635495 to your computer and use it in GitHub Desktop.
Save THEtheChad/1635495 to your computer and use it in GitHub Desktop.
Cross browser function to identify viewport size
function viewport(){
var w=window,d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0];
// Standards compliant browsers (mozilla/netscape/opera/IE7): window.innerWidth & window.innerHeight
// IE6 in standards compliant mode: documentElement.clientWidth & documentElement.clientHeight
// Older IE6
// document.getElementsByTagName('body')[0].clientWidth &
// document.getElementsByTagName('body')[0].clientHeight
return {
x: w.innerWidth||e.clientWidth||g.clientWidth,
y: w.innerHeight||e.clientHeight||g.clientHeight
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment