简体   繁体   中英

Web mobile reliable height

Does anybody knows how can I get the exact client height on a mobile device using JavaScript? I need to have the visible height (all page height except the keyboard (if displayed) and the address bar (if visible)). I tried with window.innerHieght and document.documentElement.clientHeight but the returned values are not always reliable. On iOS and Android, randomically when loading the page and showing/hideing the keyboard, the height is the height without the keyboard even if the keyboard is not visible.

Seems you can get answer from here: How to calculate height of viewable area (ie, window height minus address & bookmark bars) in mobile Safari for web app?

For example on ios7 safari:

  • window.innerHieght is 529px which is the viewport height

  • screen.availHeight is 548px which is the window.innerHeight plus address height

  • screen.height is 568px which is the screen.availHeight plus status bar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM