简体   繁体   English

screen.width / height提供有关屏幕分辨率的错误信息

[英]screen.width/height give wrong info about screen resolution

My screen have resolution 1200 x 800 but this script give me 1429 x 893 我的屏幕分辨率为1200 x 800,但此脚本给了我1429 x 893

<script>
if (screen) { 
var str = "Screen width:" + screen.width + "\n" + 
          "Screen height:" +  screen.height;
alert(str);
}
</script>

Why it doesn't work? 为什么不起作用?

ps On other site this code screen.width + screen.height but when run it on localhost it give wrong info. ps在其他站点上,此代码为screen.width + screen.height但是在localhost上运行时,它将提供错误的信息。

From MDN : MDN

Internet Explorer will take into account the zoom setting when reporting the screen width. 报告屏幕宽度时,Internet Explorer将考虑缩放设置。 It will only return the real width of the screen if the zoom is set to 100%. 如果缩放比例设置为100%,它将仅返回屏幕的实际宽度。

So for some reason screen returns the wrong resolution when the browser is zoomed. 因此,由于某些原因,缩放浏览器时屏幕返回错误的分辨率。 Hitting ctrl-zero (zero on numpad) fixes that by zooming to 100%. 按下ctrl-zero (在小键盘上为零)可将其缩放到100%。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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