【问题标题】:window.innerHeight returning wrong value in iOS 11window.innerHeight 在 iOS 11 中返回错误值
【发布时间】:2018-06-04 23:45:12
【问题描述】:

我有一个 Cordova iOS 应用程序在最新版本的 cordova (8) 和 cordova-ios (4.5.4) 上运行。我最近开始考虑更新应用程序以使用 WKWebView 而不是默认的 UIWebView,但我发现在 iOS 11(在 iPad mini 上测试)中,webview 有时会报告错误的 innerHeight。

这是index.html中的相关代码:

<meta name="viewport" content="initial-scale=1, width=device-width, height=device-height, viewport-fit=cover">

<style type="text/css">
    html, body {
        height: 100%;
    }
</style>

这就是我尝试读取属性的方式(都在deviceready 处理程序之后):

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    var calcHeight = window.screen.height - window.innerHeight;
}

window.screen.height 的计算结果始终为 1024,这很好,但 window.innerHeight 有时会返回 1004(这是预期值),但有时会返回 460。

任何想法可能会发生什么?

提前致谢

【问题讨论】:

  • 键盘小部件有时不会出现是吗?
  • @Keith,感谢您的回复。实际上,我在那个 html 页面中有几个输入,我似乎对软键盘没有任何问题。
  • 浏览器中的软键盘影响innerHeight,我通常做的是附加到窗口调整大小事件以在需要时更新。

标签: javascript ios cordova wkwebview


【解决方案1】:

【讨论】:

  • 我做到了。我实际上把它放在了问题中。
  • 嗯.. document.documentElement.clientHeight 工作正常吗?
  • 我已经能够在几个不同的 iOS 版本的 iPad 上进行测试,document.documentElement.clientHeight 似乎返回了正确的值。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-31
  • 2015-12-26
  • 2018-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多