现有答案不正确:Detect real screen resolution (ignoring browser zoom etc.)
它不会显示屏幕分辨率,而是显示文档大小。
即使在应用缩放的情况下,是否有办法在 Firefox 中获得屏幕分辨率?
最佳答案
好的,感谢https://github.com/mp31415 我有一个可行的解决方案:
var isIE = function () {
if(navigator.appName === "Microsoft Internet Explorer") {
return true;
} else if(navigator.appName === "Netscape" && /Trident/.test(navigator.userAgent)) { // IE 11
return true;
}
return false;
};
var isFF = function () {
return !!navigator.userAgent.match(/firefox/i);
};
var sw = screen.width;
var sh = screen.height;
var zoom = 1;
if (this.isIE()) {
zoom = screen.deviceXDPI / screen.systemXDPI;
zoom = this.round5(zoom*100)/100;
}
else if (this.isFF()) {
zoom = window.devicePixelRatio;
}
if (zoom != 1) {
sh = this.round10(sh * zoom);
sw = this.round10(sw * zoom);
}
此代码返回针对 Retina 显示屏缩放的分辨率,但在其他方面工作正常。
关于javascript - 在 Firefox 中获取与缩放无关的屏幕分辨率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30557404/