function alertSize() {
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
window.alert( 'Width = ' + myWidth );
window.alert( 'Height = ' + myHeight );
}[url]http://www.howtocreate.co.uk/tutorials/javascript/browserwindow[/url]
本文介绍了一个JavaScript函数,用于获取当前浏览器窗口的宽度和高度。通过判断不同的浏览器环境,该函数能够兼容多种浏览器,并准确地返回窗口的实际大小。
634

被折叠的 条评论
为什么被折叠?



