Get device height in javascript from non full screen UIWebView

孤人 提交于 2019-12-25 06:32:32

问题


I try to distinguish an Iphone 5 device in a non full screen UIWebview (320x216) from javascript. I am using the screen height as switch as that seems the only way to do this in javascript.

The problem is that the usual way to do this reports either 0 or the height of the UIWebview, not the height of the device.

document.body.offsetHeight //returns 216
screen.availHeight //returns 0
document.documentElement.clientHeight //returns 216
window.innerHeight //returns 216
screen.height //returns 0

Does anybody know of a method to do this? I unfortunately don't have control over the objective c code for the UIWebview.


回答1:


I know you said you tried this already but screen.availHeight returns 568 for an iPhone 5, even when the actual UIWebView frame is much smaller (i.e. 216). I am on iOS 7.




回答2:


Did u used this document.write("Total Height: " + screen.height); screen.height , The height property returns the total height of the visitor's screen, in pixels.



来源:https://stackoverflow.com/questions/14155907/get-device-height-in-javascript-from-non-full-screen-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!