I need to dynamically get the screen size of all mobile devices from a webpage using Javascript.
I have tried this:
//get window's size
if (document.body && document.body.offsetWidth) {
windowsWidth = document.body.offsetWidth;
windowsHeight = document.body.offsetHeight;
}
if (document.compatMode=='CSS1Compat' &&
document.documentElement &&
document.documentElement.offsetWidth ) {
windowsWidth = document.documentElement.offsetWidth;
windowsHeight = document.documentElement.offsetHeight;
}
if (window.innerWidth && window.innerHeight) {
windowsWidth = window.innerWidth;
windowsHeight = window.innerHeight;
}
But on iPad I get this size: 980 x 1080 (not the real 768 x 1024).
Thanks
Mauro
Getting the screen dimensions on iPad requires reading the width and height properties of the screen object.
var height = screen.height;
var width = screen.width;
These will provide 768 and 1024 depending on orientation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With