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
2 Answers
Reset to default 6Try 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
版权声明:本文标题:javascript - $(window).width() not working in IE9 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741663758a2391185.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论