获取与Firefox中缩放无关的屏幕分辨率 [英] Get screen resolution independent of zoom in Firefox

查看:192
本文介绍了获取与Firefox中缩放无关的屏幕分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现有答案不正确:检测实际屏幕分辨率(忽略浏览器)缩放等)

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

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

有没有办法在Firefox中获得屏幕分辨率,即使应用了缩放?

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

推荐答案

好的,感谢 https://github.com/mp31415
我有一个可行的解决方案:

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

此代码返回Retina显示的缩放分辨率,但工作正常。

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

这篇关于获取与Firefox中缩放无关的屏幕分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆