js获取各种浏览器窗口可视部分大小(可视部分不包含工具栏、标签栏等)

js获取各种浏览器窗口可视宽度和高度(不包含工具栏和标签栏)、

function getViewportSize(w){
  w= w || window;
  //除了IE8以及更早版本外,其它浏览器都能用
  if(w.innerWidth != null){ return { w:w.innerWidth, h:w.innerHeight } };
  //对标准模式下的IE或任何浏览器
  var d=w.document;
  if(document.compatMode == "CSS1Compat"){
    return { w:d.documentElement.clientWidth, 
             h:d.documentElement.clientHeight }
  }
  //对怪异模式下的浏览器
  return { w:d.body.clientWidth , h:d.body.clientHeight }
}
let aaa = getViewportSize(); 
aaa.w是可见宽度
aaa.h是可见高度

猜你喜欢

转载自www.cnblogs.com/wangweizhang/p/11358349.html
今日推荐