ie6 window.resize 事件无效
在做一个监测窗口改变大小的程序时,
发现window.resize在ie6下居然只有在放大的时候才会生效,缩小的时候并不会生效!
[php]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Left Tree</title>
<script type="text/javascript">
function ResizeTree()
{
var width = document.body.clientWidth;
alert(width);
}
window.οnresize=ResizeTree;
</script>
</head>
<body>
</body>
</html>
[/php]
最后发现:
去掉头部html dtd声明即可!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
IE 和 FIREFOX 都兼容的事件写法
window.οnlοad=function()
{
yourfunction();
}
window.οnresize=function()
{
yourfunction();
}