Get Window Height and Width (Cross-Compatible)


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

Returns window size as object.
winsize.x = window width;
winsize.y = window height;


Copy this code and paste it in your HTML
  1. function getWindowSize(){
  2. var x = 0;
  3. var y = 0;
  4. if (self.innerHeight)
  5. {
  6. x = self.innerWidth;
  7. y = self.innerHeight;
  8. }
  9. else if (document.documentElement && document.documentElement.clientHeight)
  10. {
  11. x = document.documentElement.clientWidth;
  12. y = document.documentElement.clientHeight;
  13. }
  14. else if (document.body)
  15. {
  16. x = document.body.clientWidth;
  17. y = document.body.clientHeight;
  18. }
  19. return {"x":x,"y":y};
  20. }

URL: http://perpetualtechnologies.net

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.