Javascript 如何在Nexus7中读取宽度和高度?
我正在尝试使用fallowing js代码读取nexus 7 2013设备的宽度和高度:Javascript 如何在Nexus7中读取宽度和高度?,javascript,android,html,css,Javascript,Android,Html,Css,我正在尝试使用fallowing js代码读取nexus 7 2013设备的宽度和高度: while (!(width && height)){ // alert("if this msg shows more then once - the height or width has been falsly read as 0"); width = e.clientWidth || g.clientWidth ||
while (!(width && height)){
// alert("if this msg shows more then once - the height or width has been falsly read as 0");
width = e.clientWidth || g.clientWidth || w.innerWidth;
height = e.clientHeight || g.clientHeight || w.innerHeight;
}
它可以在所有设备上正常工作,但nexus 7 2013除外。只有在这个设备上,它有时读取1920的宽度,有时读取960的宽度
有人能帮我理解为什么会发生这种情况,以及如何克服这个问题吗?
谢谢大家! 试试这个
<script>
var y=screen.availHeight;
var x=screen.availWidth;
alert("Your resolution is "+x+" X "+y);
</script>
我认为,当窗口聚焦时,有时会出现问题