关于浏览器兼容性的实例代码
程序员文章站
2022-04-24 12:55:36
...
<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();
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();
以上就是关于浏览器兼容性的实例代码的详细内容,更多请关注其它相关文章!
上一篇: Webpack框架使用总结