我需要使用 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;
}
但在 iPad 上我得到这个尺寸:980 x 1080(不是真正的 768 x 1024)。
谢谢
毛罗
最佳答案
获取 iPad 上的屏幕尺寸需要读取屏幕对象的宽度和高度属性。
var height = screen.height;
var width = screen.width;
这些将根据方向提供 768 和 1024。
关于javascript - 如何在 Javascript 中获取 iPad 屏幕宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10777547/