我有一个下面的代码,试图确定是否有人通过手机或桌面,通过其设备的innerWidth访问我的网站。但是,当我尝试从手机中获取innerWidth时,它显示我的手机的宽度是980像素?虽然我的手机的宽度没有任何宽度,我的手机的宽度为300px左右,高度为500px左右。在我的桌面上,它显示1280px,这是正确的。我的问题是,为什么它显示我的手机宽度错误?除非有什么我不正确的理解?innerWidth在手机上没有得到正确的宽度
<?php
include("ajaxLink.php");
?>
<script>
$(function(){
var width = window.innerWidth;
alert(width);
if (width > 500) {
alert("going to index");
window.location = "/";
} //end of if (width > 500)
else {
alert("going to mobile");
window.location = "mobile.php";
} //end of else (width <= 500)
});
</script>
__around:300px__?通过你的设备的规格。在铬'设备模式下测试这个代码' – Rayon
@RayonDabre我们在谈论宽度,从左到右,从上到下的高度,对吧? – frosty