问题描述
使用Android模拟器genymotion(800 * 1280) ,获取window.innerWidth是错误的,描述如下:
安装android应用后,我在事件window.onload = function(){alert(window.innerWidth)}中设置js语言来获取视口宽度,但答案是320(这是错误的),然后单击一个按钮,触发事件$(button).click(function(){alert(window.innerWidth)}),但答案是602(在右边)。
当然, <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
已附加到HTML5头。
尝试使用Chrome移动调试器(800 * 1280)时没有问题。答案是800。
<button value="click me get the width"/>
<script>
//we all know window.innerWidth can get the viewport width
window.onload=functon(){
alert(window.innerWidth)
}//get the wrong answer 320
$(button).click(function(){
alert(window.inerWidth)})//get the right answer 602
</script>
1楼
Dhruv Nagarajan
0
2019-01-17 19:06:51
试试这个吧。
我的用例是按自定义分辨率渲染网站,而不一定是设备的分辨率。
我无法得到与所期望的结果WebView
任何责任。
AdvancedWebView
首次尝试工作。