码迷,mamicode.com
首页 > Web开发 > 详细

JS兼容的方式来获取浏览器的宽度

时间:2015-07-11 21:25:23      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

<script type="text/javascript">
        
        //need to wait until onload so body is available    
        window.onload = function(){
        
            function getWindowWidth(){
                if (window.innerWidth){
                    return window.innerWidth;
                } else if (document.documentElement.clientWidth){
                    return document.documentElement.clientWidth;
                } else if (document.body.clientWidth){
                    return document.body.clientWidth;
                }
            }
            
                    
            //determine if the browser has Netscape-style plugins
            var hasNSPlugins = !!(navigator.plugins && navigator.plugins.length);
            
            //determine if the browser has basic DOM Level 1 capabilities
            var hasDOM1 = !!(document.getElementById && document.createElement && 
                           document.getElementsByTagName);
            
            alert("Window width: " + getWindowWidth());
            alert("Supports Netscape plugins? " + hasNSPlugins);
            alert("Supports Core DOM 1?

" + hasDOM1); } </script>


JS兼容的方式来获取浏览器的宽度

标签:

原文地址:http://www.cnblogs.com/lcchuguo/p/4639300.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!