我需要使用Javascript从网页动态获取所有移动设备的屏幕大小.
我试过这个:
//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;
}
Run Code Online (Sandbox Code Playgroud)
但在iPad上我得到这个尺寸:980 x 1080(不是真正的768 x 1024).
谢谢
毛罗