screen.width / height提供有关屏幕分辨率的错误信息 [英] screen.width/height give wrong info about screen resolution

查看:151
本文介绍了screen.width / height提供有关屏幕分辨率的错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的屏幕分辨率为1200 x 800但这个脚本给了我1429 x 893

My screen have resolution 1200 x 800 but this script give me 1429 x 893

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

为什么它不起作用?

PS在其他网站上这个代码 screen.width + screen.height 但是当它在localhost上运行它会给出错误的信息。

p.s. On other site this code screen.width + screen.height but when run it on localhost it give wrong info.

推荐答案

来自 MDN



报告屏幕宽度时,Internet Explorer将考虑缩放设置。如果缩放设置为100%,它将仅返回
屏幕的实际宽度。

Internet Explorer will take into account the zoom setting when reporting the screen width. It will only return the real width of the screen if the zoom is set to 100%.

因此由于某种原因浏览器缩放时,屏幕返回错误的分辨率。
点击 ctrl-zero (numpad为零)通过缩放到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%.

这篇关于screen.width / height提供有关屏幕分辨率的错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆