admin管理员组

文章数量:1302342

I am doing something like follow:

// get the screen height and width 
var maskHeight = $(document).height(); 
var maskWidth = $(window).width();

// calculate the values for center alignment
var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2);

But looks like it's not working in IE9.

I am doing something like follow:

// get the screen height and width 
var maskHeight = $(document).height(); 
var maskWidth = $(window).width();

// calculate the values for center alignment
var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2);

But looks like it's not working in IE9.

Share edited Feb 9, 2012 at 9:03 Aman Aggarwal 4,0154 gold badges28 silver badges39 bronze badges asked Aug 10, 2011 at 19:02 Saurabh KumarSaurabh Kumar 16.7k49 gold badges140 silver badges219 bronze badges 4
  • 2 What exactly is it doing wrong? – FishBasketGordo Commented Aug 10, 2011 at 19:04
  • he is somehow shifting to right – Saurabh Kumar Commented Aug 10, 2011 at 19:10
  • @Saurabh You should cache your $('#dialog-box') reference: var dialog = $('#dialog-box')[0]; (on page load), and then $(dialog) whenever you need it... – Šime Vidas Commented Aug 10, 2011 at 19:13
  • @Saurabh $(window).width() should work just fine. The problem is somewhere else... Can you provide a screenshot of the issue? – Šime Vidas Commented Aug 10, 2011 at 19:14
Add a ment  | 

2 Answers 2

Reset to default 6

Try this:

var maskWidth = window.innerWidth;
var maskHeight = window.innerHeight;

Or in IE 6+ in standards pliant mode:

var maskWidth = document.documentElement.clientWidth;
var maskHeight = document.documentElement.clientHeight;

Use:

$(window).innerHeight();
$(window).innerWidth();

本文标签: javascript(window)width() not working in IE9Stack Overflow