Browser dependent viewport size


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var viewportWidth;
  2. var viewportHeight;
  3. if(window.innerWidth) {
  4. // normal browsers (incl. scrollbars)
  5. viewportWidth = window.innerWidth;
  6. viewportHeight = window.innerHeight;
  7. } else {
  8. // IE (and all other browsers ... minus the scrollbar(s))
  9. viewportWidth = document.documentElement.clientWidth;
  10. viewportHeight = document.documentElement.clientHeight;
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.