当屏幕 CSS 像素比大于 1 时,在不同的浏览器上获取相同的 window.screen.height 和 windo

Get the same window.screen.height and window.screen.width on different browsers when screen CSS pixel ratio is higher than 1

本文关键字:获取 浏览器 window windo height screen 像素 CSS 屏幕 大于      更新时间:2023-09-26

我需要用javascript检测window.screen.height和window.screen.width。但是在css像素比大于1的设备上进行测试,我在多个浏览器中得到了不同的结果。

在三星Galaxy S3上进行测试,分辨率:1280x720和CSS像素比:2 我得到以下结果:

库存浏览器: 1280x720火狐: 1280x720歌剧: 640x360铬:640x360

是否可以在不同的浏览器上获得相同的结果?

亲切问候

$(window).width();
$(window).height();

适用于所有类型的设备,包括 iOS。在您的文档就绪功能中使用它。并在CSS中使用媒体查询像素比率 这里是所有移动媒体查询标准设备媒体查询的链接