天天看點

js擷取浏覽器高度

// 擷取浏覽器高寬
function getWindowClientWH() {
      var winWidth = , winHeight = ;
      // 擷取視窗寬度
      if (window.innerWidth)
          winWidth = window.innerWidth;
      else if ((document.body) && (document.body.clientWidth))
          winWidth = document.body.clientWidth;
      // 擷取視窗高度
      if (window.innerHeight)
          winHeight = window.innerHeight;
      else if ((document.body) && (document.body.clientHeight))
          winHeight = document.body.clientHeight;
      // 通過深入Document内部對body進行檢測,擷取視窗大小
      if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {
          winHeight = document.documentElement.clientHeight;
          winWidth = document.documentElement.clientWidth;
     }
      return {
          width : winWidth,
          height : winHeight
     };
};