【问题标题】:Get screen resolution independent of zoom in Firefox在 Firefox 中获取独立于缩放的屏幕分辨率
【发布时间】:2015-12-19 16:46:17
【问题描述】:

现有答案不正确:Detect real screen resolution (ignoring browser zoom etc.)

它不会显示屏幕分辨率,而是显示文档大小。

有没有办法在 Firefox 中获得屏幕分辨率,即使在应用缩放时也是如此?

【问题讨论】:

标签: javascript screen


【解决方案1】:

好的,感谢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 显示器缩放的分辨率,但在其他方面工作正常。

【讨论】:

  • 2015 年的浏览器嗅探,真的吗?
  • 我不明白你的意思是什么意思:)
  • 好的,明白了:)。今天仍然存在一些实施差异,需要浏览器检测。
  • @Valentin 不一定是这个。您可以使用typeof 测试相关属性是否存在,并仅在可用时使用它们。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-07-27
  • 2010-09-16
  • 2023-04-11
  • 1970-01-01
  • 2016-10-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多