clark Posted March 4, 2014 Share Posted March 4, 2014 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 Link to comment Share on other sites More sharing options...
Sebi Posted March 4, 2014 Share Posted March 4, 2014 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 More sharing options...
Recommended Posts