浏览器程序设计笔记

来源:互联网 发布:南阳理工网络教学平台 编辑:程序博客网 时间:2024/06/05 11:32
history对象:

1、history.length属性保存着历史记录的URL数量。初始时,该值为1。如果当前窗口先后访问了三个网址,history.length属性等于3

2、history对象提供了一系列方法,允许在浏览历史之间移动,包括go()、back()和forward()

//后退一页
history.go(-1)
//前进一页
history.go(1);
//前进两页
history.go(2);

 Location对象:

   Location.href 返回整个当前url,若对其赋值:
location.href="http://www.highya.com" 则跳转其url
location.host 返回域名和端口号,如:www.highya.com:80
lcation.hostname 返回域名
location.port 返回端口
location.pathname 返回域名后第一个斜框后的字符串
location.hash 跳到本页的某个锚
location.search 取url?后的部分

Navigator对象:

getCurrentPosition(successCallback,errorCallback)
appCodeName      返回浏览器的代码名。 
appMinorVersion  返回浏览器的次级版本。 
appName              返回浏览器的名称。 
appVersion       返回浏览器的平台和版本信息。 
browserLanguage 返回当前浏览器的语言。 
cookieEnabled      返回指明浏览器中是否启用 cookie 的布尔值。 
cpuClass       返回浏览器系统的 CPU 等级。 
onLine       返回指明系统是否处于脱机模式的布尔值。 
platform        返回运行浏览器的操作系统平台。 
systemLanguage   返回 OS 使用的默认语言。 
userAgent       返回由客户机发送服务器的 user-agent 头部的值。 
userLanguage       返回 OS 的自然语言设置。 

screen对象:

screen对象用来表明客户端的能力,其中包括浏览器窗口外部的显示器的信息,如像素高度和宽度等

属性              说明
height            屏幕的像素高度
width             屏幕的像素宽度
availHeight       屏幕的像素高度减去系统部件高度之后的值(只读)
availWidth        屏幕的像素宽度减去系统部件宽度之后的值(只读)
left              当前屏幕距左边的像素距离[firefox返回0,chrome和IE不支持]
top               当前屏幕距上方的像素距离[firefox返回0,chrome和IE不支持]
availLeft         未被系统部件占用的最左侧的像素值(只读)[chrome和firefox返回0,IE不支持]
availTop          未被系统部件占用的最上方的像素值(只读)[chrome和firefox返回0,IE不支持]
bufferDepth       读、写用于呈现屏外位图的位数[IE返回0,chrome和firefox不支持]
colorDepth        用于表现颜色的位数(只读)[IE8-返回32,其他浏览器返回24]
pixelDepth        屏幕的位深(只读)[IE8-不支持,其他浏览器返回24]
deviceXDPI        屏幕实际的水平DPI(只读)[IE返回96,chrome和firefox不支持]
deviceYDPI        屏幕实际的垂直DPI(只读)[IE返回96,chrome和firefox不支持]
logicalXDPI       屏幕逻辑的水平DPI(只读)[IE返回96,chrome和firefox不支持]
logicalYDPI       屏幕逻辑的垂直DPI(只读)[IE返回96,chrome和firefox不支持]
updateInterval      读、写以毫秒表示的屏幕刷新时间间隔[IE返回0,chrome和firefox不支持]
fontSmoothingEnabled     是否启用了字体平滑(只读)[IE返回true,chrome和firefox不支持
 

确定用户的浏览器:

2种方法:特性检测、浏览器探嗅

特性检测:

   function geoSuccess(position) {
                var coords = position.coords;
                    var latitude = coords.latitude;
                var longitude = coords.longitude;
                var message = "You're at " + latitude + ", " + longitude
                alert(message);
            }
            function geoError(errorObj) {
                alert(errorObj.message);
            }
            if (typeof navigator.geolocation != "undefined") {
                navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
            } else {
                alert("This page uses geolocation, and your browser doesn't support it.");
            }

浏览器探嗅:

    function getBrowserName() {
            var lsBrowser = navigator.userAgent;
            if (lsBrowser.indexOf("MSIE") >= 0) {
                return "MSIE";
            } else if (lsBrowser.indexOf("Firefox") >= 0) {
                return "Firefox";
            } else if (lsBrowser.indexOf("Chrome") >= 0) {
                return "Chrome";
            } else if (lsBrowser.indexOf("Safari") >= 0) {
                return "Safari";
            } else if (lsBrowser.indexOf("Opera") >= 0) {
                return "Opera";
            } else {
                return "UNKNOWN";
            }
        }
        function getBrowserVersion() {
            var ua = navigator.userAgent;
            var browser = getBrowserName();
            var findIndex = ua.indexOf(browser) + browser.length + 1;
            var browserVersion = parseFloat(ua.substring(findIndex, findIndex + 3));
            return browserVersion;
        }
        var browserName = getBrowserName();
        var browserVersion = getBrowserVersion();
        if (browserName == "MSIE") {
            if (browserVersion < 9) {
                document.write("Your version of Internet Explorer is too old");
            } else {
                document.write("Your version of Internet Explorer is fully supported");
            }
        } else if (browserName == "Firefox") {
            document.write("Firefox is fully supported");
        } else if (browserName == "Safari") {
            document.write("Safari is fully supported");
        } else if (browserName == "Chrome") {
            document.write("Chrome is fully supported");
        } else if (browserName == "Opera") {
            document.write("Opera is fully supported");
        } else {
            document.write("Sorry this browser version is not supported.");
        }

原创粉丝点击