Get screen resolution independent of zoom in Firefox

别等时光非礼了梦想. 提交于 2019-12-08 10:42:34

问题


The existing answer is incorrect: Detect real screen resolution (ignoring browser zoom etc.)

It will not show the screen resolution, but rather the document size.

Is there a way to get screen resolution in Firefox, even when zoom is applied?


回答1:


OK, thanks to https://github.com/mp31415 I have a working solution:

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);
}

This code returns resolution scaled for Retina displays but otherwise works fine.



来源:https://stackoverflow.com/questions/30557404/get-screen-resolution-independent-of-zoom-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!