Как определить - какою у юзера браузер?
From : Artem Babadzhanyants
Как определить - какою у юзера браузер?
// Browser propeties check library. Version 1.02
// (C) Zalog 2000. Permission granted to reuse and distribute.
// e-mail: zalog@pyramid-studio.com
function Browser(){
this.checkScreen=Browser_checkScreen;
this.getCookieVal=Browser_getCookieVal;
this.fixCookieDate=Browser_fixCookieDate;
this.getCookie=Browser_getCookie;
this.setCookie=Browser_setCookie;
this.deleteCookie=Browser_deleteCookie;
this.getHostName=Browser_getHostName;
this.getHostAddress=Browser_getHostAddress;
this.agent=navigator.userAgent.toLowerCase();
(navigator.appName)?this.name=navigator.appName:this.name=null;
(navigator.appCodeName)?this.codeName=navigator.appCodeName:this.codeName=nu
ll;
(navigator.securityPolicy)?this.securityPolicy=navigator.securityPolicy:this
..securityPolicy=null;
this.versionHi=parseInt(navigator.appVersion);
this.version=parseFloat(navigator.appVersion);
if(navigator.cpuClass){
this.cpu=navigator.cpuClass.toLowerCase();
this.cpuClass="Unknown CPU class, including Sun SPARC";
if(navigator.cpuClass.indexOf("x86")!= -1) this.cpuClass="Intel
processor";
if((navigator.cpuClass.indexOf("68k")!= -1)||(navigator.cpuClass.indexOf("pp
c")!= -1)) this.cpuClass="Motorola processor";
if(navigator.cpuClass.indexOf("alpha")!= -1) this.cpuClass="Digital
processor";
}else{
this.cpu=null;
this.cpuClass=null;
}
(navigator.onLine )?this.onLine=navigator.onLine:this.onLine=null;
if(navigator.cookieEnabled)this.cookieEnabled=navigator.cookieEnabled;
else{
var expdate=new Date();
expdate.setTime(expdate.getTime()+(365*24*60*60*1000));
this.fixCookieDate(expdate);
this.setCookie("test_js","safe to delete",expdate,"/");
(this.getCookie("test_js"))?this.cookieEnabled=true:this.cookieEnabled=false
;
this.deleteCookie("test_js","/");
}
if(navigator.language)this.language=navigator.language;
else if(navigator.browserLanguage)this.language=navigator.browserLanguage;
else this.language=null;
(navigator.systemLanguage)?this.systemLanguage=navigator.systemLanguage:this
..systemLanguage=null;
(navigator.userLanguage)?this.userLanguage=navigator.userLanguage:this.userL
anguage=null;
this.Netscape=((this.agent.indexOf('mozilla')!=-1)&&(this.agent.indexOf('spo
ofer')==-1)&&(this.agent.indexOf('compatible')==-1)&&(this.agent.indexOf('op
era')==-1)&&(this.agent.indexOf('webtv')==-1));
this.Netscape2=(this.Netscape&&(this.versionHi==2));
this.Netscape3=(this.Netscape&&(this.versionHi==3));
this.Netscape4=(this.Netscape&&(this.versionHi==4));
this.Netscape4up=(this.Netscape&&(this.versionHi>=4));
this.Netscape5=(this.Netscape&&(this.versionHi==5));
this.Netscape5up=(this.Netscape&&(this.versionHi>=5));
this.NavigatorOnly=(this.Netscape&&((this.agent.indexOf(";nav")!=-1)||(this.
agent.indexOf("; nav")!=-1)));
this.IE=(this.agent.indexOf("msie") != -1);
this.IE3=(this.IE&&(this.versionHi<4));
this.IE4=(this.IE&&(this.versionHi==4)&&(this.agent.indexOf("msie
5.0")==-1));
this.IE4up=(this.IE&&(this.versionHi>=4));
this.IE5=(this.IE&&(this.versionHi==4)&&(this.agent.indexOf("msie
5.0")!=-1));
this.IE5up=(this.IE&&!this.IE3&&!this.IE4);
if(this.IE5){
this.versionHi=parseInt(this.agent.substr(this.agent.indexOf("5.")));
this.version=parseFloat(this.agent.substr(this.agent.indexOf("5.")));
}
this.AOL=(this.agent.indexOf("aol")!= -1);
this.AOL3=(this.AOL&&this.IE3);
this.AOL4=(this.AOL&&this.IE4);
this.Opera=(this.agent.indexOf("opera")!=-1);
this.WebTV=(this.agent.indexOf("webtv")!=-1);
if(this.Netscape2||this.IE3)this.jsVersion=1.0;
else if(this.Netscape3||this.Opera)this.jsVersion=1.1;
else
if((this.Netscape4&&(this.version<=4.05))||this.IE4)this.jsVersion=1.2;
else
if((this.Netscape4&&(this.version>4.05))||this.IE5)this.jsVersion=1.3;
else if(this.Netscape5)this.jsVersion=1.4;
else if(this.Netscape&&(this.versionHi>5))this.jsVersion=1.4;
else if(this.IE&&(this.versionHi>5))this.jsVersion=1.3;
else if(_jsVersion>1.3)this.jsVersion=_jsVersion;
else this.jsVersion=0.0;
this.vbVersion=vbVer;
this.osWin=((this.agent.indexOf("win")!=-1)||(this.agent.indexOf("16bit")!=-
1));
this.osWin95=((this.agent.indexOf("win95")!=-1)||(this.agent.indexOf("window
s 95")!=-1));
this.osWinCE=((this.agent.indexOf("wince")!=-1)||(this.agent.indexOf("window
s ce")!=-1)||(this.agent.indexOf("win ce")!=-1));
this.osWin16=((this.agent.indexOf("win16")!=-1)||(this.agent.indexOf("16bit"
)!=-1)||(this.agent.indexOf("windows
3.1")!=-1)||(this.agent.indexOf("windows 16-bit")!=-1));
this.osWin31=((this.agent.indexOf("windows
3.1")!=-1)||(this.agent.indexOf("win16")!=-1)||(this.agent.indexOf("windows
16-bit")!=-1));
this.osWin98=((this.agent.indexOf("win98")!=-1)||(this.agent.indexOf("window
s 98")!=-1));
this.osWinNT=((this.agent.indexOf("winnt")!=-1)||(this.agent.indexOf("window
s nt")!=-1));
this.osWin2000=(this.osWinNT||(this.agent.indexOf("nt 5.0")!=-1));
this.osWin32=(this.osWin95||this.osWinNT||this.osWin98||this.osWin2000||((th
is.versionHi>=4)&&(navigator.platform=="Win32"))||(this.agent.indexOf("win32
")!=-1)||(this.agent.indexOf("32bit")!=-1));
this.osOS2=((this.agent.indexOf("os/2")!=-1)||(navigator.appVersion.indexOf(
"OS/2")!=-1)||(this.agent.indexOf("ibm-webexplorer")!=-1));
this.osMac=(this.agent.indexOf("mac")!=-1);
this.osMac68k=(this.osMac&&((this.agent.indexOf("68k")!=-1)||(this.agent.ind
exOf("68000")!=-1)));
this.osMacPPC=(this.osMac &&
((this.agent.indexOf("ppc")!=-1)||(this.agent.indexOf("powerpc")!=-1)));
this.osSun=(this.agent.indexOf("sunos")!=-1);
this.osSun4=(this.agent.indexOf("sunos 4")!=-1);
this.osSun5=(this.agent.indexOf("sunos 5")!=-1);
this.osSuni86=(this.osSun&&(this.agent.indexOf("i86")!=-1));
this.osIrix=(this.agent.indexOf("irix")!=-1);
this.osIrix5=(this.agent.indexOf("irix 5")!=-1);
this.osIrix6=((this.agent.indexOf("irix
6")!=-1)||(this.agent.indexOf("irix6")!=-1));
this.osHPUx=(this.agent.indexOf("hp-ux")!=-1);
this.osHPUx9=(this.osHPUx&&(this.agent.indexOf("09.")!=-1));
this.osHPUx10=(this.osHPUx&&(this.agent.indexOf("10.")!=-1));
this.osAIX=(this.agent.indexOf("aix")!=-1);
this.osAIX1=(this.agent.indexOf("aix 1")!=-1);
this.osAIX2=(this.agent.indexOf("aix 2")!=-1);
this.osAIX3=(this.agent.indexOf("aix 3")!=-1);
this.osAIX4=(this.agent.indexOf("aix 4")!=-1);
this.osLinux=(this.agent.indexOf("inux")!=-1);
this.osSCO=(this.agent.indexOf("sco")!=-1)||(this.agent.indexOf("unix_sv")!=
-1);
this.osUnixWare=(this.agent.indexOf("unix_system_v")!=-1);
this.osMPRAS=(this.agent.indexOf("ncr")!=-1);
this.osReliant=(this.agent.indexOf("reliantunix")!=-1);
this.osDEC=((this.agent.indexOf("dec")!=-1)||(this.agent.indexOf("osf1")!=-1
)||(this.agent.indexOf("dec_alpha")!=-1)||(this.agent.indexOf("alphaserver")
!=-1)||(this.agent.indexOf("ultrix")!=-1)||(this.agent.indexOf("alphastation
")!=-1));
this.osSinix=(this.agent.indexOf("sinix")!=-1);
this.osBSD=(this.agent.indexOf("bsd")!=-1);
this.osFreeBSD=(this.agent.indexOf("freebsd")!=-1);
this.osOpenBSD=(this.agent.indexOf("openbsd")!=-1);
this.osNetBSD=(this.agent.indexOf("netbsd")!=-1);
this.osBSDi=(this.agent.indexOf("bsdi")!=-1);
this.osUnix=((this.agent.indexOf("x11")!=-1)||this.osSun||this.osIrix||this.
osHPUx||this.osSCO||this.osUnixWare||this.osMPRAS||this.osReliant||this.osDE
C||this.osSinix||this.osAIX||this.osLinux||this.osBSD||this.osFreeBSD);
this.osVMS=((this.agent.indexOf("vax")!=-1)||(this.agent.indexOf("openvms")!
=-1));
this.hostName=null;
this.hostAddress=null;
this.hostName=this.getHostName();
this.hostAddress=this.getHostAddress();
this.checkScreen();
}
function Browser_checkScreen(){
if (top.screen){
(screen.pixelDepth)?this.pixelDepth=screen.pixelDepth:this.pixelDepth=null;
(screen.colorDepth)?this.colorDepth=screen.colorDepth:this.colorDepth=null;
if(screen.width&&screen.height){
this.screenWidth=screen.width;
this.screenHeight=screen.height;
this.screenResolution=this.screenWidth+"x"+this.screenHeight;
}else{
this.screenWidth=null;
this.screenHeight=null;
this.screenResolution=null;
}
if(screen.availWidth&&screen.availHeight){
this.availWidth=screen.availWidth;
this.availHeight=screen.availHeight;
this.availResolution=this.availWidth+"x"+this.availHeight;
}else{
this.availWidth=null;
this.availHeight=null;
this.availResolution=null;
}
if(this.screenWidth&&this.screenHeight&&this.colorDepth)this.Resolution=this
..screenWidth+"x"+this.screenHeight+"x"+this.colorDepth;
else this.Resolution = null;
}else{
this.pixelDepth=null;
this.colorDepth=null;
this.availWidth=null;
this.availHeight=null;
this.availResolution=null;
this.screenWidth=null;
this.screenHeight=null;
this.screenResolution=null;
this.Resolution=null;
}
if(window.innerWidth)this.innerWidth=window.innerWidth;
else{
if(document.body){
if(document.body.clientWidth)
this.innerWidth=document.body.clientWidth;
}else this.innerWidth=null;
}
if(window.innerHeight)this.innerHeight=window.innerHeight;
else{
if(document.body){
if(document.body.clientHeight)this.innerHeight=document.body.clientHeight;
} else this.innerHeight=null;
}
(this.innerWidth&&this.innerHeight)?this.innerResolution=this.innerWidth+"x"
+this.innerHeight:this.innerResolution=null;
(window.outerWidth)?this.outerWidth=window.outerWidth:this.outerWidth=null;
(window.outerHeight)?this.outerHeight=window.outerHeight:this.outerHeight=nu
ll;
(this.outerWidth &&
this.outerHeight)?this.outerResolution=this.outerWidth+"x"+this.outerHeight:
this.outerResolution=null;
(window.offscreenBuffering)?this.offscreenBuffering=window.offscreenBufferin
g:this.offscreenBuffering=null;
if(window.frameRate)this.frameRate=window.frameRate;
else this.frameRate=null;
}
function Browser_getCookieVal(offset){
var endstr=document.cookie.indexOf(";",offset);
if(endstr==-1)endstr=document.cookie.length;
return unescape(document.cookie.substring(offset,endstr));
}
function Browser_fixCookieDate(date){
var base=new Date(0);
var skew=base.getTime();
if(skew>0)date.setTime(date.getTime()-skew);
}
function Browser_getCookie(name){
var arg=name+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while(i<clen){
var j=i+alen;
if(document.cookie.substring(i,j)==arg)return this.getCookieVal(j);
i=document.cookie.indexOf(" ",i)+1;
if(i==0)break;
}
return null;
}
function Browser_setCookie(name,value,expires,path,domain,secure){
document.cookie=name+"="+escape(value)+((expires)?";
expires="+expires.toGMTString():"")+((path)?"; path="+path:"")+((domain)?";
domain="+domain:"")+((secure)?"; secure":"");
}
function Browser_deleteCookie(name,path,domain){
if(this.getCookie(name))document.cookie=name+"="+((path)?";
path="+path:"")+((domain)?"; domain="+domain:"")+"; expires=Thu, 01-Jan-70
00:00:01 GMT";
}
function Browser_getHostName(){
if(navigator.appName.lastIndexOf('Netscape')!=-1)
if(navigator.javaEnabled()==1){
window.onerror=null;
hostAddress=java.net.InetAddress.getLocalHost();
return(hostAddress.getHostName());
}
return null;
}
К огавлению
|