修正IE6 IE7的window.resize bug


<!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>

原文地址:https://www.cnblogs.com/amylis_chen/p/1712699.html