javascript - 如何在 Javascript 中获取 iPad 屏幕宽度

标签 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;
}

但在 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/

相关文章:

javascript - Chrome 扩展程序 : Create a new tab by click a button

macos - OSX 应用程序 : Get max resolution of the user's display (Swift)

html - 如何根据屏幕大小更改图标(图片)的大小?

android - 如何更改 Xamarin Android Player 屏幕大小

javascript - Aurelia 中的类似物 $apply 或 $digest(Angular)

javascript - 如何使用接口(interface)类型执行动态类型测试?

javascript - webpack 和 babel-polyfill : Can't resolve 'core-js/modules/es6.array.map' in source directory

javascript - .htaccess 受密码保护的网站在 Ipad 上重新加载每个页面时都需要密码

iphone - 如何使 iphone 和 iphone4-retina 兼容的应用程序(在 cocos2d 中完成)轻松适应 ipad?

iphone - UIScrollview 中的格式化文本