1.获取浏览器位置及兼容写法
screenLeft、screenTop:除FIREFOX以外的浏览器都支持;
screenX、screenY:除IE以外的所有浏览器都支持
兼容写法
var leftX = typeof window.screenLeft == "number" screenLeft : screenX;
var topY = typeof window.screenTop == "number" screenTop : screenY;
2.获取浏览器窗口大小及兼容写法
firefox 内容大小:innerWidth,innerHeight
firefox 浏览器大小:outerWidth,outerHeight
chrome中innerWidth = outerWidth,innerHeight = outerHeight
IE7以上:document.documentElement.clientWidth , document.documentElement.clientHeight;
IE6:document.body.clientWidth , document.body.clientHeight;
判断是否为IE6
if(document.compatMode == "CSS1Compat" ){alert("这不是IE6");}else{alert("这是IE6");}
兼容所有浏览器的写法
var width = window.innerWidth;
var height = window. innerHeight;
if(typeof widht != "number"){
if(document.compatMode == "CSS1Compat"){//如果不是IE6
width = document.documentElement.clientWdith;
height = documnet.documentElement.clientHeight;
}else{
width = document.body.clientWidth;
height = document.body.clientHeight;
}
}
浙公网安备 33010602011771号