亲测兼容各种浏览器(IE、Firefox、chrome、360、Opera。。。) 获取浏览器的窗口的宽度和高度:
<script type=”text/javascript”>
var winWidth = 0;
var sinHeight = 0;
//获取宽度
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){
winWidth = document.documentElement.clientWidth;
winHeight = document.documentElement.clientHeight;
}
alert(winWidth+’,'+winHeight);
</script>
//获取屏幕的宽度和高度
<script>
var winWidth = screen.width;
var winHeight = screen.height;
alert(winWidth+’,'+winHeight);
</sciprt>