太乱了,先放放

/*
            
 * 智能机浏览器版本信息:
            
 *
            
 */


var browser = {


    versions : function() {

    
    var u = navigator.userAgent, app = navigator.appVersion;

    
    return {//移动终端浏览器版本信息

        
        trident : u.indexOf('Trident') > -1, //IE内核

    
    presto : u.indexOf('Presto') > -1, //opera内核

    
    webKit : u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核

    
    gecko : u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核

    
    mobile : !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), //是否为移动终端

    
    ios : !!u.match(/(i[^;]+;( U;)? CPU.+Mac OS X)/), //ios终端

    
    android : u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器

    
    iPhone : u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器

    
    iPad : u.indexOf('iPad') > -1, //是否iPad

    
    webApp : u.indexOf('Safari') == -1
    //是否web应该程序,没有头部与底部

    
};

}(),


language : (navigator.browserLanguage || navigator.language).toLowerCase()


}

/*手机系统*/
 var ua = (navigator.userAgent || navigator.vendor || window.opera);
            if (ua!=null) {
                var uaName = ua.toLowerCase();
                if (/android/i.test(uaName)) metaElement = androidUrl;
                else
                {   if (/ip(hone|od)/i.test(uaName)) metaElement = iphoneUrl;
                    else {
                    if (/symbian/i.test(uaName)) metaElement = symbianUrl;
                        else {
                            if (/windows (ce|phone)/i.test(uaName))  metaElement = windowsPhoneUrl;
                            else url = defaultUrl;
                        }
                    }
                }
                //document.writeln(uaName);
            }
            else { url = defaultUrl; }




网页可见区域宽: document.body.clientWidth
网页可见区域高: document.body.clientHeight
网页可见区域宽: document.body.offsetWidth (包括边线的宽)
网页可见区域高: document.body.offsetHeight (包括边线的高)
网页正文全文宽: document.body.scrollWidth
网页正文全文高: document.body.scrollHeight
网页被卷去的高: document.body.scrollTop
网页被卷去的左: document.body.scrollLeft
网页正文部分上: window.screenTop
网页正文部分左: window.screenLeft
屏幕分辨率的高: window.screen.height
屏幕分辨率的宽: window.screen.width
屏幕可用工作区高度: window.screen.availHeight
屏幕可用工作区宽度: window.screen.availWidth




<script language="javascript" type="text/javascript">
  var device_width = document.body.scrollWidth;
        var UI_width = 640;
        var test = '480px';
        var deviceRatio = window.devicePixelRatio;alert(device_width);
        function checkOS() {
        
            //默认的地址
            var defaultUrl = 'index.htm';
            //如果检测到是Android系统需要跳转的地址
            var androidUrl = 'android.htm';
            //如果检测到是iphone/ipod需要跳转的地址
            var iphoneUrl = 'iphone.htm';
            //symbian跳转地址
            var symbianUrl = 'symbian.htm';
            //windows phone跳转地址
            var windowsPhoneUrl = 'winphone.htm';
            var metaElement = '<meta name="viewport" />'; var ua = (navigator.userAgent || navigator.vendor || window.opera);
            
            if (ua!=null) {
                var uaName = ua.toLowerCase();
                if (/android/i.test(uaName)) {
                    var get_target_densitydpi = UI_width / device_width * deviceRatio * 160;
                    metaElement = '<meta name="viewport" content="target-densitydpi='+get_target_densitydpi+', width=device-width, user-scalable=no,initial-scale=1" />';
                }
                else
                {   if (/ip(hone|od|ad)/i.test(uaName)) {
                    metaElement = '<meta name="viewport" content="target-densitydpi=device-dpi, width=480px, user-scalable=no,initial-scale=1" />';
                } else {
                    if (/symbian/i.test(uaName)) {
                        metaElement = '<meta name="viewport" content="width=480px, user-scalable=no,initial-scale=1" />';
                    }else {
                            if (/windows (ce|phone)/i.test(uaName))  {
                                metaElement = '<meta name="viewport" content="width=480px, user-scalable=no,initial-scale=1" />';
                            }
                            
                        }
                    }
                }
            }
            //alert(metaElement);
            document.write(metaElement);
        }
        checkOS();
    </script>

























原来:
     HTML里是document.body;
     XHTML里是document.documentElement;
都指的是<body>节点(OR元素)

可以这样兼容:
function getBodyObj(){
    return (document.documentElement) ? document.documentElement : document.body ;
}
在DHTML文档中对documentElement的说明是:Object that receives the reference to the document element,The root node of a typical HTML document is the html object.

 
Microsoft? Internet Explorer 6 的新增内容
当你使用 !DOCTYPE 声明指定标准兼容模式的时候,此对象将不再代表文档内容所渲染的整个表面。该对象当然可从其内容中获得其大小,但你也可以像 div 对象那样精确设置其大小。
也就是说在HTML4.0标准下用document.body,在XHTML标准下就要换成document.documentElement。
  XHTM下document.body仅仅表示body对象,而不能代表文档内容所渲染的整个表面。
  HTML下document.body.clientHeight表示浏览器的可视高度,XHTML下则是document.documentElement.clientHeight。document.body.clientHeight在XHTML下仅表示body的可视高度。在HTML4.0下用document.body.scrollTop;而在XHTML下则是document.documentElement.scrollTop,之前的document.body.scrollTop是恒为0的。
-------------------------------
与其相关:
 

document.documentElement.clientWidth为0
 
 

关于获取各种浏览器可见窗口大小:
<script>
function getInfo(){
var s = "";
s = " 网页可见区域宽:" document.body.clientWidth;
s = " 网页可见区域高:" document.body.clientHeight;
s = " 网页可见区域宽:" document.body.offsetWidth " (包括边线和滚动条的宽)";
s = " 网页可见区域高:" document.body.offsetHeight " (包括边线的宽)";
s = " 网页正文全文宽:" document.body.scrollWidth;
s = " 网页正文全文高:" document.body.scrollHeight;
s = " 网页被卷去的高(ff):" document.body.scrollTop;
s = " 网页被卷去的高(ie):" document.documentElement.scrollTop;
s = " 网页被卷去的左:" document.body.scrollLeft;
s = " 网页正文部分上:" window.screenTop;
s = " 网页正文部分左:" window.screenLeft;
s = " 屏幕分辨率的高:" window.screen.height;
s = " 屏幕分辨率的宽:" window.screen.width;
s = " 屏幕可用工作区高度:" window.screen.availHeight;
s = " 屏幕可用工作区宽度:" window.screen.availWidth;
 


s = "
你的屏幕设置是 " window.screen.colorDepth " 位彩色";
s = " 你的屏幕设置 " window.screen.deviceXDPI " 像素/英寸";
//alert (s);
}
getInfo();
</script>
在我本地测试当中:
在IE、FireFox、Opera下都可以使用
document.body.clientWidth
document.body.clientHeight
即可获得,很简单,很方便。
而在项目当中:
Opera仍然使用
document.body.clientWidth
document.body.clientHeight
可是IE和FireFox则使用
document.documentElement.clientWidth
document.documentElement.clientHeight
原来是W3C的标准在作怪啊
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
如果在页面中添加这行标记的话 在IE中:
document.body.clientWidth ==> BODY对象宽度
document.body.clientHeight ==> BODY对象高度
document.documentElement.clientWidth ==> 可见区域宽度
document.documentElement.clientHeight ==> 可见区域高度
在FireFox中:
document.body.clientWidth ==> BODY对象宽度
document.body.clientHeight ==> BODY对象高度
document.documentElement.clientWidth ==> 可见区域宽度
document.documentElement.clientHeight ==> 可见区域高度
?
在Opera中:
document.body.clientWidth ==> 可见区域宽度
document.body.clientHeight ==> 可见区域高度
document.documentElement.clientWidth ==> 页面对象宽度(即BODY对象宽度加上Margin宽)
document.documentElement.clientHeight ==> 页面对象高度(即BODY对象高度加上Margin高)
而如果没有定义W3C的标准,则
IE为:
document.documentElement.clientWidth ==> 0
document.documentElement.clientHeight ==> 0
FireFox为:
document.documentElement.clientWidth ==> 页面对象宽度(即BODY对象宽度加上Margin宽)document.documentElement.clientHeight ==> 页面对象高度(即BODY对象高度加上Margin高)
Opera为:
document.documentElement.clientWidth ==> 页面对象宽度(即BODY对象宽度加上Margin宽)document.documentElement.clientHeight ==> 页面对象高度(即BODY对象高度加上Margin高)

 

---------------------------------------------
 
在设计页面时可能经常会用到固定层的位置,这就需要获取一些html对象的坐标以更灵活的设置目标层的坐标,这里可能就会用到document.body.scrollTop等属性,但是此属性在xhtml标准网页或者更简单的说是带<!DOCTYPE ..>标签的页面里得到的结果是0,如果不要此标签则一切正常,那么在xhtml页面怎么获得body的坐标呢,当然有办法-使用document.documentElement来取代document.body,可以这样写
例:
var top = document.documentElement.scrollTop || document.body.scrollTop;
在javascript里||是个好东西,除了能用在if等条件判断里,还能用在变量赋值上。那么上例等同于下例。
例:
var top = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
这么写可以得到很好的兼容性。
相反,如果不做声明的话,document.documentElement.scrollTop反而会显示为0。













jQuery 获取屏幕高度、宽度

做手机Web开发做浏览器兼容用到了,所以在网上找了些汇总下。

alert($(window).height()); //浏览器当前窗口可视区域高度

alert($(document).height()); //浏览器当前窗口文档的高度

alert($(document.body).height());//浏览器当前窗口文档body的高度

alert($(document.body).outerHeight(true));//浏览器当前窗口文档body的总高度 包括border padding margin

alert($(window).width()); //浏览器当前窗口可视区域宽度

alert($(document).width());//浏览器当前窗口文档对象宽度

alert($(document.body).width());//浏览器当前窗口文档body的高度

alert($(document.body).outerWidth(true));//浏览器当前窗口文档body的总宽度 包括border padding margin

 

// 获取页面的高度、宽度

function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {

        xScroll = window.innerWidth + window.scrollMaxX;

        yScroll = window.innerHeight + window.scrollMaxY;

    } else {

        if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac    

            xScroll = document.body.scrollWidth;

            yScroll = document.body.scrollHeight;

        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari    

            xScroll = document.body.offsetWidth;

            yScroll = document.body.offsetHeight;

        }

    }

    var windowWidth, windowHeight;

    if (self.innerHeight) { // all except Explorer    

        if (document.documentElement.clientWidth) {

            windowWidth = document.documentElement.clientWidth;

        } else {

            windowWidth = self.innerWidth;

        }

        windowHeight = self.innerHeight;

    } else {

        if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode    

            windowWidth = document.documentElement.clientWidth;

            windowHeight = document.documentElement.clientHeight;

        } else {

            if (document.body) { // other Explorers    

                windowWidth = document.body.clientWidth;

                windowHeight = document.body.clientHeight;

            }

        }

    }       

    // for small pages with total height less then height of the viewport    

    if (yScroll < windowHeight) {

        pageHeight = windowHeight;

    } else {

        pageHeight = yScroll;

    }    

    // for small pages with total width less then width of the viewport    

    if (xScroll < windowWidth) {

        pageWidth = xScroll;

    } else {

        pageWidth = windowWidth;

    }

    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);

    return arrayPageSize;

}

 

// 滚动条

document.body.scrollTop;

$(document).scrollTop();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值