开发者

Detect real screen resolution (ignoring browser zoom etc.)

开发者 https://www.devze.com 2023-02-17 06:52 出处:网络
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 buil

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

or (jquery)

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

精彩评论

暂无评论...
验证码 换一张
取 消