Mau*_*neo 9 javascript ipad screen-size
我需要使用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).
谢谢
毛罗
获取 iPad 上的屏幕尺寸需要读取屏幕对象的宽度和高度属性。
var height = screen.height;
var width = screen.width;
Run Code Online (Sandbox Code Playgroud)
根据方向,这些将提供 768 和 1024。