javascript:当有多个显示器时查找屏幕分辨率
我使用这段代码来确定客户端屏幕分辨率,然后记录它
<input type="hidden" id="DFF63C7E-FB32-49AE-8ADA-3AB5C4834FB0" name="DFF63C7E-FB32-49AE-8ADA-3AB5C4834FB0"/>
<input type="hidden" id="565C07CF-0D37-41DE-B47D-A247E9BD231B" name="565C07CF-0D37-41DE-B47D-A247E9BD231B" />
<script type="text/javascript" language="javascript">
document.getElementById("DFF63C7E-FB32-49AE-8ADA-3AB5C4834FB0").value = screen.width;
document.getElementById("565C07CF-0D37-41DE-B47D-A247E9BD231B").value = screen.height;
</script>
在我的本地主机中测试时工作正常,但我从生产日志中发现屏幕分辨率始终为 480x640。有谁知道为什么会发生这种情况?
我做了一些更多的挖掘,发现我可以更改主显示器的分辨率,无论我是否在主/辅助显示器中打开浏览器,它总是会给我主显示器的分辨率。
有没有办法根据浏览器打开的显示器来获取屏幕分辨率?
显然,下一个问题是,如果分辨率中途发生变化(例如从控制面板)或将浏览器从一个浏览器移到另一个浏览器,是否有办法用 JS 检测/更新它?
I am using this piece of code to determine the client screen resolution, and then logging it
<input type="hidden" id="DFF63C7E-FB32-49AE-8ADA-3AB5C4834FB0" name="DFF63C7E-FB32-49AE-8ADA-3AB5C4834FB0"/>
<input type="hidden" id="565C07CF-0D37-41DE-B47D-A247E9BD231B" name="565C07CF-0D37-41DE-B47D-A247E9BD231B" />
<script type="text/javascript" language="javascript">
document.getElementById("DFF63C7E-FB32-49AE-8ADA-3AB5C4834FB0").value = screen.width;
document.getElementById("565C07CF-0D37-41DE-B47D-A247E9BD231B").value = screen.height;
</script>
It worked OK when testing in my localhost, but what I found out from the production logs was that the screen resolution was always 480x640. Does anyone know why this happens ?
And I did some more digging and found that I could change the resolution of my primary monitor and regardless of whether I open my browser in primary/secondary monitor, it would always give me the resolution of the primary monitor.
Is there any way to get the screen resolution based on which monitor the browser gets opened ?
And obviously the next question is, if the resolution changes midway (say from control panel) or moving the browser from one to another, is there a way to detect/update it with JS ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将以下行添加到您的页面。
它将调整您的窗口大小到完整的宽度和高度..
例如使用
Add the following line to your page.
it will resize your window to full width and height..
for example use
尝试以下方法来获取窗口的尺寸:
Try this to get the dimensions of the window instead: