ie确实有此问题,我的解决办法是:
在页面加载时使用setInterval 一直比较窗口宽度,
当宽度改变时调用方法,
页面加载完取消interval.
代码如下:
[code="html"]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
test1.html
<!---->
<br>
<!--</p>
<pre><code>wresize(function(){alert(2)});
function wresize(fn){
var width,height,interval;
window.onresize=fn;
window.onload=function(){
if(interval)clearInterval(interval);
}
interval=setInterval(function(){
var w=getWinSize();
width=width||w.width;
height=height||w.height;
if(width!=w.width||height!=w.height){
fn();
width=w.width;
height=w.height;
}
},200);
}
function getWinSize(){
var winW, winH;
if(window.innerHeight) { // all except IE
winW = window.innerWidth; winH = window.innerHeight;
} else if (document.documentElement&&document.documentElement.clientHeight){ // IE 6 Strict Mode
winW = document.documentElement.clientWidth;
winH = document.documentElement.clientHeight;
} else if (document.body){// other
winW = document.body.clientWidth;
winH = document.body.clientHeight;
}
return {"width":winW, "height":winH};
}
</code></pre>
<p>//--><br>
[/code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
test1.html
<!---->
<br>
<!--</p>
<pre><code>wresize(function(){alert(2)});
function wresize(fn){
var width,height,interval;
window.onresize=fn;
window.onload=function(){
if(interval)clearInterval(interval);
}
interval=setInterval(function(){
var w=getWinSize();
width=width||w.width;
height=height||w.height;
if(width!=w.width||height!=w.height){
fn();
width=w.width;
height=w.height;
}
},200);
}
function getWinSize(){
var winW, winH;
if(window.innerHeight) { // all except IE
winW = window.innerWidth; winH = window.innerHeight;
} else if (document.documentElement&&document.documentElement.clientHeight){ // IE 6 Strict Mode
winW = document.documentElement.clientWidth;
winH = document.documentElement.clientHeight;
} else if (document.body){// other
winW = document.body.clientWidth;
winH = document.body.clientHeight;
}
return {"width":winW, "height":winH};
}
</code></pre>
<p>//--><br>