Jump to content

What is the correct way to detect the size of a HTML page?


clark
 Share

Recommended Posts

I want to detect the size of an HTML page. 

How do I do this in JavaScript (no JQ). 

I actually spent a while looking, there are loads of ways, but many answers related to 2-3-4 years ago.  Is there just a standard modern way which works cross browser?

Also, how does Orientation fit into this.  Does width refer to the landscape or portrait orientation and is this consistent?

Thanks :D

Link to comment
Share on other sites

var body = document.getElementsByTagName('body')[0],x = window.innerWidth || document.documentElement.clientWidth || body.clientWidth,y = window.innerHeight|| document.documentElement.clientHeight|| body.clientHeight;alert(x);

To get the orientation you can check window.orientation but.. that is not really consistent.

Some devices have different portrait/landscape default values.

 

The best thing you can do (imo) is to simply check if the width is bigger than the height and then assume that you are most likely in landscape mode. Portrait vice versa.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...