您的位置:首页 > 其它

修正IE6 IE7的window.resize bug

2010-04-15 15:08 309 查看
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta content="IE=6" http-equiv="X-UA-Compatible"/>
<title>fix ie6 resize bug by 司徒正美</title>

<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Resize</title>
<script type="text/javascript">
if(!Array.prototype.map)
Array.prototype.map = function(fn,scope) {
var result = [],ri = 0;
for (var i = 0,n = this.length; i < n; i++){
if(i in this){
result[ri++] = fn.call(scope ,this[i],i,this);
}
}
return result;
};

var getWindowSize = function(){
return ["Height","Width"].map(function(name){
return window["inner"+name] ||
document.compatMode === "CSS1Compat" && document.documentElement[ "client" + name ]
|| document.body[ "client" + name ]
});
}
window.onload = function(){
if(!+"\v1" && !document.querySelector) { // for IE6 IE7
document.body.onresize = resize;
} else {
window.onresize = resize;
}
var text = document.getElementById("text")
function resize() {
text.innerHTML = getWindowSize().join(" : ");
}
}
</script>

</head>
<body>
<h1>修正IE6 IE7中window.onresize 被多次执行的bug</h1>
<div id="text">这里是用来显示窗口大小</div>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: