检测实际屏幕分辨率(忽略浏览器缩放等) [英] Detect real screen resolution (ignoring browser zoom etc.)

查看:142
本文介绍了检测实际屏幕分辨率(忽略浏览器缩放等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用JavaScript(客户端至少)获得真正的屏幕分辨率,但是有IE和Firefox的问题,因为当您使用浏览器的内置缩放时,它们会改变这一点。

I need to get the real screen resolution using JavaScript (client-side at least), but having issues with both IE and Firefox as they tend to change this when you use the browser's built-in zoom.

如何以跨浏览器友好的方式做到这一点?

How can this be done in a cross-browser friendly manner?

推荐答案

function getDimension() {
  var width = 0, height = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    height = window.innerHeight;
    width = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    height = document.documentElement.clientHeight;
    width = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    height = document.body.clientHeight;
    width = document.body.clientWidth;
  }
  window.alert( 'Width = ' + width + 'Height = ' + height);
}

或(jquery)

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

这篇关于检测实际屏幕分辨率(忽略浏览器缩放等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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