<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <script type="text/javascript"> function browserinfo(){ var Browser_Name=navigator.appName; var Browser_Version=parseFloat(navigator.appVersion); var Browser_Agent=navigator.userAgent; var Actual_Version,Actual_Name; var is_IE=(Browser_Name=="Microsoft Internet Explorer");//判读是否为ie浏览器 var is_NN=(Browser_Name=="Netscape");//判断是否为netscape浏览器 var is_op=(Browser_Name=="Opera");//判断是否为Opera浏览器 if(is_NN){ //upper 5.0 need to be process,lower 5.0 return directly if(Browser_Version>=5.0){ if(Browser_Agent.indexOf("Netscape")!=-1){ var Split_Sign=Browser_Agent.lastIndexOf("/"); var Version=Browser_Agent.lastIndexOf(" "); var Bname=Browser_Agent.substring(0,Split_Sign); var Split_sign2=Bname.lastIndexOf(" "); Actual_Version=Browser_Agent.substring(Split_Sign+1,Browser_Agent.length); Actual_Name=Bname.substring(Split_sign2+1,Bname.length); } if(Browser_Agent.indexOf("Firefox")!=-1){ var Split_Sign=Browser_Agent.lastIndexOf("/"); var Version=Browser_Agent.lastIndexOf(" "); Actual_Version=Browser_Agent.substring(Split_Sign+1,Browser_Agent.length); Actual_Name=Browser_Agent.substring(Version+1,Split_Sign); } if(Browser_Agent.indexOf("Safari")!=-1){ if(Browser_Agent.indexOf("Chrome")!=-1){ var Split_Sign=Browser_Agent.lastIndexOf(" "); var Version=Browser_Agent.substring(0,Split_Sign);; var Split_Sign2=Version.lastIndexOf("/"); var Bname=Version.lastIndexOf(" "); Actual_Version=Version.substring(Split_Sign2+1,Version.length); Actual_Name=Version.substring(Bname+1,Split_Sign2); } else{ var Split_Sign=Browser_Agent.lastIndexOf("/"); var Version=Browser_Agent.substring(0,Split_Sign);; var Split_Sign2=Version.lastIndexOf("/"); var Bname=Browser_Agent.lastIndexOf(" "); Actual_Version=Browser_Agent.substring(Split_Sign2+1,Bname); Actual_Name=Browser_Agent.substring(Bname+1,Split_Sign); } } } else{ Actual_Version=Browser_Version; Actual_Name=Browser_Name; } } else if(is_IE){ var Version_Start=Browser_Agent.indexOf("MSIE"); var Version_End=Browser_Agent.indexOf(";",Version_Start); Actual_Version=Browser_Agent.substring(Version_Start+5,Version_End) Actual_Name=Browser_Name; if(Browser_Agent.indexOf("Maxthon")!=-1||Browser_Agent.indexOf("MAXTHON")!=-1){ var mv=Browser_Agent.lastIndexOf(" "); var mv1=Browser_Agent.substring(mv,Browser_Agent.length-1); mv1="遨游版本:"+mv1; Actual_Name+="(Maxthon)"; Actual_Version+=mv1; } } else if(Browser_Agent.indexOf("Opera")!=-1){ Actual_Name="Opera"; var tempstart=Browser_Agent.indexOf("Opera"); var tempend=Browser_Agent.length; Actual_Version=Browser_Version; } else{ Actual_Name="Unknown Navigator" Actual_Version="Unknown Version" } /*------------------------------------------------------------------------------ --Your Can Create new properties of navigator(Acutal_Name and Actual_Version) -- --Userage: -- --1,Call This Function. -- --2,use the property Like This:navigator.Actual_Name/navigator.Actual_Version;-- ------------------------------------------------------------------------------*/ navigator.Actual_Name=Actual_Name; navigator.Actual_Version=Actual_Version; /*--------------------------------------------------------------------------- --Or Made this a Class. -- --Userage: -- --1,Create a instance of this object like this:var browser=new browserinfo;-- --2,user this instance:browser.Version/browser.Name; -- ---------------------------------------------------------------------------*/ this.Name=Actual_Name; this.Version=Actual_Version; } browserinfo(); document.write("你使用的浏览器是:"+navigator.userAgent); document.write("<br>"); document.write("你使用的浏览器是:"+navigator.Actual_Name+",版本号:"+navigator.Actual_Version); </script> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <body> </body> </html>
------------------------------------------------------------------------------------------------------------
function Brower(){ } Brower.prototype.getBrowerInfo =function(){ var reg; if(document.all){ this.isIE=true; reg=/MSIE ([^;]+)/ } else{ this.isFF=true; reg=/Firefox\/(\d+)/ } var m=reg.exec(navigator.userAgent) this.version=parseInt(m[1]); } Brower.prototype.toString=function(){ return "浏览器\t"+(this.isIE?"IE":"Firefox")+"\n版 本\t"+this.version; } var b=new Brower(); b.getBrowerInfo(); alert(b)
---------------------------------------------------------------------
var sUserAgent = navigator.userAgent; var fAppVersion = parseFloat(navigator.appVersion); //比较浏览器版本大小 function compareVersions(sVersion1,sVersion2){ var aVersion1 = sVersion1.split("."); var aVersion2 = sVersion2.split("."); if(aVersion1.length>aVersion2.length){ for(var i=0;i<aVersion1.length;i++) aVersion2.push("0"); }else if(aVersion1.length<aVersion2.length){ for(var i=0;i<aVersion2.length;i++) aVersion1.push("0"); } for(var i=0;i<aVersion1.length;i++){ if(aVersion1[i]<aVersion2[i]) return -1; else if(aVersion1[i]>aVersion2[i]) return 1; } return 0; } //检测是否Opera浏览器(判断是否IE需要排除这个可能) var isOpera = sUserAgent.indexOf("Opera")>-1; //检测是否Safari(判断是否FF需要排除这个可能) var isKHTML = sUserAgent.indexOf("KHTML")>-1 || sUserAgent.indexOf("Konqueror")>-1 || sUserAgent.indexOf("AppleWebKit")>-1; //检测IE var isIE = sUserAgent.indexOf("compatible") > -1 &&sUserAgent.indexOf("MSIE") > -1 &&!isOpera; var isMinIE4 = isMinIE5 = isMinIE5_5 = isMinIE6 = isMinIE7 = false; if(isIE){ var reIE = new RegExp("MSIE (\\d+\\.\\d+);"); reIE.test(sUserAgent); var fIEVersion = parseFloat(RegExp["$1"]); isMinIE4 = fIEVersion >=4; isMinIE5 = fIEVersion >=5; isMinIE5_5 = fIEVersion >=5.5; isMinIE6 = fIEVersion >=6; isMinIE7 = fIEVersion >=7; } //检测Firfox var isFF = sUserAgent.indexOf("Firefox")>-1&&!isKHTML; var isMinFF1 = isMinFF2 =isMinFF3 = false; if(isFF){ var reFF = new RegExp("Firefox\\/(\\d+\\.\\d+(?:\\.\\d+\\.\\d+)?)"); reFF.test(sUserAgent); isMinFF1 = compareVersions(RegExp["$1"],"1.0")