JavaScript to obtain browser information and operating system information

Source: Internet
Author: User
<Title> browser detection </title> <MCE: Script Type = "text/JavaScript"> <! -- /*  ** Client information detection ** @ Type: Class * @ Author: [bi] cjj http://www.imcjj.com * @ version: 0.1.3 build 061108 * @ note:  */  Function  Tclientcheck (){  This . Useragent = Navigator. useragent;  This . Getbrowse = Tclientcheck_browse;  This . Getos = Tclientcheck_ OS;  This . Browsekernel = "unknown" ;  This . Isdomsupport = False ; //  Dom supported?      If  (Document. getelementbyid ){  This . Isdomsupport = True  ;}}  /*  ** Browser information detection ** @ Type: Public Method * @ parameter: none * @ return: browser name * @ Author: [bi] cjj http://www.imcjj.com * @ time: 2006-11-7 last update at 2006-11-8 * @ note:  */ Function  Tclientcheck_browse (){  VaR SUA = This  . Useragent;  //  Check IE browser      If (Navigator. appname = "Microsoft Internet Explorer" )){  //  Detects the opera that simulates ie browsing. Edit at 2006-11-08 (ver 0.1.2)          If (SUA. indexof ('Opera ')! =-1 ){  This . Browsekernel = 'presto' ;  If (Window. Opera && Document. childnodes ){  Return 'Opera 7 +' ;}  Else  {  Return 'Opera 6 -' ;}}  This . Browsekernel = 'trigger' ;  If (SUA. indexof ('maxthon ')! =-1){  Return 'Maxthon' ;}  If (SUA. indexof ('tencenttraveler ')! =-1 ){ //  Ver 0.1.3              Return 'Tencent tt' ;}  If  (Document. getelementbyid ){  Return "Ie5 +" ;}  Else  { Return "Ie4 -" ;}}  //  Detect gecko browsers      If (SUA. indexof ('gecko ')! =-1 ){  This . Browsekernel = 'gecko' ;  If (Navigator. Vendor = "Mozilla "){ Return "Mozilla" ;}  If (Navigator. Vendor = "Firebird "){ Return "Firebird";}  If (SUA. indexof ('Firefox ')! =-1 ){ Return 'Firefox' ;}  Return "Gecko" ;}  //  Netscape Browser      If (SUA. indexof ('netscape ')! =-1 ){  This . Browsekernel = 'gecko' ;  If (Document. getelementbyid ){  Return "Netscape 6 +" ;}  Else  {  Return 'Netscape 5 -' ;}}  //  Detect Safari      If (SUA. indexof ('safari ')! =-1 ){ This . Browsekernel = 'khtml '; Return 'Safari' ;} If (SUA. indexof ('konqueror ')! =-1 ){ This . Browsekernel = 'khtml '; Return 'Konqueror' ;}  //  Currently, it is recognized that browsers with the fastest web browsing speed occupy a large amount of system resources.      If (SUA. indexof ('Opera ')! =-1 ){  This . Browsekernel = 'presto' ;  If (Window. Opera && Document. childnodes ){ Return 'Opera 7 +' ;}  Else  {  Return 'Opera 6 -' ;}  Return 'Opera' ;}  If (SUA. indexof ('hotjava ')! =-1 )&& Typeof (Navigator. accentcolorname) = 'undefined '){ Return 'Hotjava' ;}  If (Document. All & document. getelementbyid & navigator. savepreferences & (SUA. indexof ('netfront') <0) & navigator. appname! = 'Blazer '){ Return 'Escape 5' ;}  //  Konqueror/Safari/omniweb 4.5 +      If (Navigator. Vendor = 'kde' | (document. childnodes &&(! Document. All | navigator. accentcolorname )&&! Navigator. taintenabled )){ This . Browsekernel = 'khtml '; Return 'Kde' ;}  If (Navigator. _ ice_version ){ Return 'Icebrowser' ;}  If (Window. scriptengine & scriptengine (). indexof ('inscript') + 1 ){  If  (Document. createelement ){  Return 'Icab 3 +' ;}  Else  {  Return 'Icab 2 -' ;}} If (Document. Layers &&! Document. Classes ){ Return 'New web 4.2 -' ;}  If (Document. Layers &&! Navigator. mimetypes ['*']) { Return 'Escape 4' ;}  If (Navigator. appname. indexof ('webtv') + 1 ){ Return 'Webtv' ;}  If (SUA. indexof ('netg ')! =-1 ){ Return 'Netgem netbox';}  If (SUA. indexof ('opentv ')! =-1 ){ Return 'Opentv' ;}  If (SUA. indexof ('ipanel ')! =-1 ){ Return 'Ipanel microbrowser' ;}  If (Document. getelementbyid &&! Document. childnodes ){ Return 'Clue browser' ;}  If (Document. getelementbyid & (SUA. indexof ('netfront ')! =-1) | navigator. appname = 'blazer ')){Return 'Netfront 3 +' ;}  If (SUA. indexof ('msie ') + 1) & window. activexobject ){ Return 'Bucket Internet Explorer' ;}  Return "Unknown" ;}  /*  ** Operating system information detection ** @ Type: Public Method * @ parameter: none * @ return: Operating System name * @ Author: [bi] cjj http://www.imcjj.com * @ time: 2006-11-7 * @ note:  */  Function  Tclientcheck_ OS (){ VaR SUA = This  . Useragent. tolowercase ();  If (SUA. indexof ('win ')! =-1 ){  If (SUA. indexof ("nt 5.2 ")! =-1 ){ Return "Windows 2003" ;}  If (SUA. indexof ("nt 5.1 ")! =-1) | (SUA. indexof ("XP ")! =-1 )){ Return "Windows XP" ;}  If (SUA. indexof ('nt 5.0 ')! =-1) | (SUA. indexof ('20140901 ')! =-1 )){ Return 'Windows 2000' ;}  If (SUA. indexof ("winnt ")! =-1) | (SUA. indexof ("Windows NT ")! =-1 )){ Return "Windows NT" ;}  If (SUA. indexof ("Win98 ")! =-1) | (SUA. indexof ("Windows 98 ")! =-1 )){ Return "Windows 98" ;}  Return "Windows" ;}  If (SUA. indexof ('linux ')! =-1 ){ Return 'Linux' ;}  If (SUA. indexof ("FreeBSD ")! =-1 ){ Return 'Freebsd' ;}  If (SUA. indexof ('x11 ')! =-1 ){ Return 'Unix' ;}  If (SUA. indexof ('mac ')! =-1 ){ Return "Mac" ;}  If (SUA. indexof ("SunOS ")! =-1 ){Return 'Sun OS' ;}  If (SUA. indexof ("OS/2 ")! =-1) | (navigator. appversion. indexof ("OS/2 ")! =-1) | (SUA. indexof ("IBM-webexplorer ")! =-1 )){ Return "OS 2" }  If (Navigator. Platform = 'palmos '){ Return 'Palm OS' ;}  If (Navigator. Platform = 'wince ') | (navigator. Platform = 'windows ce') | (navigator. Platform = 'bucket pc ')){ Return 'Windows ce';}  If (SUA. indexof ('webtv ')! =-1 ){ Return 'Webtv platform' ;}  If (SUA. indexof ('netg ')! =-1 ){ Return 'Netg' ;}  If (SUA. indexof ('opentv ')! =-1 ){ Return 'Opentv platform' ;}  If (SUA. indexof ('symbian ')! =-1 ){ Return 'Symbian';}  Return "Unknown" ;}  //  --> </MCE: SCRIPT> </Head> <body> <Div id = "browseinfo"> </div>
JavaScript to get browser Information
<MCE: Script Type = "text/JavaScript"> <! --VaROCC =NewTclientcheck ();VaROinfo = Document. getelementbyid ('browseinfo'); Oinfo. innerhtml= '<P> your browser is: <B>' + OCC. getbrowse () + '</B> </P> <p> the kernel of your browser is: <B>' + OCC. browsekernel + '</B> </P> <p> the operating system you are using is: <B>' + OCC. getos () + '</B> </P> <p> User Agent:' + OCC. useragent + '</P>';//--> </MCE: SCRIPT>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.