<script type="text/JavaScript" language="javascript">
function fnGetWidthHeight() {
var viewportwidth;
var viewportheight;
// 支持(mozilla/netscape/opera/chrome/IE7)
if (typeof window.innerWidth != 'undefined') {
viewportwidth = window.innerWidth;
viewportheight = window.innerHeight;
}
// 支持(IE6)
else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
viewportwidth = document.documentElement.clientWidth;
viewportheight = document.documentElement.clientHeight;
}
// 支持其他浏览器
else {
viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
viewportheight = document.getElementsByTagName('body')[0].clientHeight;
}
alert('Your viewport width & height is ' + viewportwidth + 'x' + viewportheight);
}
fnGetWidthHeight();
转载于:https://www.cnblogs.com/wen5211314/p/6970589.html