javascriptの深いwindow、screen、navigatorの対象

3982 ワード

a)           :
1>                        ,              。
2>         web         ,              。
3>          HTML      ,              。    


      :
var getWinPosition = function(){
	var pos={
		//window.screenX=>FF
		left:(typeof window.screenLeft === 'number')? window.screenLeft: window.screenX;
		top :(typeof window.screenTop  === "number")? window.screenTop : window.screenY;
	};
	return pos;
}
        :
var getViewPortSize = function(){
	var w = window.innerWidth,
		h = widnow.innerHeight;
	if(typeof w !== "number"){//IE
		if(document.compatMode == "CSS1Compat"){//    
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}else{//     IE6    
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	return {
		width :w,
		height:h
	}
}

b)screen                  
                               
availHeight              (      ) 
availWidth               (      ) 
bufferDepth                           
colorDepth                                
deviceXDPI                                  
deviceYDPI                                  
fontSmoothingEnabled                            
height                          
logicalXDPI                            
logicalYDPI                            
updateInterval                    
width                           

    (     )  :
var getScreenSize = function (){
	var w = screen.availWidth,
		h = screen.availHeight;
	return {
		width :w,
		height:h
	}
}

c)Navigator            
var getBrowserMessage = function (){
	var nav = navigator;
	return  "appName:"    +nav.appName    +"
"+// "appCodeName:"+nav.appCodeName+"
"+// "appVersion:" +nav.appVersion +"
"+// "userAgent:" +nav.userAgent +"
"+// user-agent HTTP "platform:" +nav.platform ;// } //FF appName:Netscape appCodeName:Mozilla appVersion:5.0 (Windows) userAgent:Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firefox/21.0 platform:Win32 var pattern = /(mozilla)(?:.*? rv:([\w.]+)|)/; //IE6.0 appName:Microsoft Internet Explorer appCodeName:Mozilla appVersion:4.0 (compatible; MSIE 6.0; Windows NT 5.1; InfoPath.2; .NET4.0C) userAgent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; InfoPath.2; .NET4.0C) platform:Win32 var pattern = /(msie) ([\w.]+)/; //chorme appName:Netscape appCodeName:Mozilla appVersion:5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11 userAgent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11 platform:Win32 var pattern = /(chrome)[ \/]([\w.]+)/; //opera appName:Opera appCodeName:Mozilla appVersion:9.80 (Windows NT 5.1; U; zh-cn) userAgent:Opera/9.80 (Windows NT 5.1; U; zh-cn) Presto/2.10.289 Version/12.02 platform:Win32 var pattern = /(opera)(?:.*version|)[ \/]([\w.]+)/; //safari appName:Netscape appCodeName:Mozilla appVersion:5.0 (Windows NT 5.1) AppleWebKit/534.54.16 (KHTML, like Gecko) Version/5.1.4 Safari/534.54.16 userAgent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.54.16 (KHTML, like Gecko) Version/5.1.4 Safari/534.54.16 platform:Win32 var pattern = /(webkit)[ \/]([\w.]+)/; : var getBrowser = function( ua ) { ua = ua.toLowerCase(); var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) || /(webkit)[ \/]([\w.]+)/.exec( ua ) || /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) || /(msie) ([\w.]+)/.exec( ua ) || ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || []; return { browser: match[ 1 ] || "", version: match[ 2 ] || "0" }; }; var nav=getBrowser(navigator.userAgent); alert(nav.browser+"----"+nav.version); d) window.location.hash="#top"; or window.location.replace("#top");