Beginner JavaScript Write a judge browser type of function (class), not very perfect, but after all, the first time to write Dongdong, commemorate!
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" > <ptml> <pead> <meta http-equiv= "con Tent-type "content=" text/html; charset=gb2312 "> <meta name=" generator "content=" PSPad editor, www.pspad.com "> <meta name=" Author "Conte Nt= "Yemoo" > <title>get Exact Browser type</title> </pead> <body> <script type= "Tex T/javascript ">/*-----------------------------------------------------------------This function can return T He actual browser name and version.----Usesage:there are two Methods ("The end of this function)----Create by Yemoo. Datetime:2006-2-3 21:53:37-----------------------------------------------------------------* * 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"); var is_nn= (browser_name== "Netscape"); if (IS_NN) {//upper 5.0 need to is Process,lower 5.0 return directly if (browser_version>=5.0) { var split_sign=browser_agent.lastindexof ("/"); var version=browser_agent.indexof ("", split_sign); var bname=browser_agent.lastindexof ("", split_sign); Actual_version=browser_agent.substring (split_sign+1,version); 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) {actual_name+= "(Maxthon)"; else if (Browser_agent.indexof ("opera")!=-1) {actual_name= "opera"; var tempstart=browser_agent.indexof ("Opera"); var tempend=browser_agent.length; Actual_version=browser_agent.substring (Tempstart+6,tempend)}} else{Actual_n Ame= "Unknown Navigator" actual_version= "Unknown Version"}/*------------------------------ --------------------------------------------------Your Can Create new properties of Navigator (Acutal_name and Ac tual_version)----Userage:----1,CA ll this Function. ----2,use the Property like This:navigator. Actual_name/navigator. Actual_version--------------------------------------------------------------------------------* */Navig Ator. 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 INS Tance:browser. Version/browser. Name; -----------------------------------------------------------------------------* *. Name=actual_name; This. Version=actual_version; } browserinfo (); document.write ("The browser you use is:" +navigator.) Actual_name+ ", Version number:" +navigator. Actual_version); </script> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]