Using JavaScript implementations to determine the current browser

Source: Internet
Author: User
Tags extend

Wrote a method to determine the current browser type and version, only in IE 8/11, Google, 360 browser (not complete) on the test

I hope you will make comments

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 ;(function ($, window, document,undefined) {if (!window.browser) {  var useragent = Navigator.userAgent.toLowerCase (), Uamatch; Window.browser = {}  /** * To determine if IE/function Isie () {return ("ActiveXObject" in window),/** * To determine whether Google Browser/if ( !uamatch) {Uamatch = Useragent.match (/chrome/([D.] +)/); if (uamatch!=null) {window.browser[' name '] = ' chrome '; window.browser[' version ' = uamatch[1];} /** * To determine if the Firefox browser/if (!uamatch) {uamatch = Useragent.match (/firefox/([D.] +)/); if (uamatch!=null) {window.browser[' name '] = ' Firefox '; window.browser[' version ' = uamatch[1];} /** * To determine whether Opera browser/if (!uamatch) {uamatch = Useragent.match (/opera. [D.] +)/); if (uamatch!=null) {window.browser[' name '] = ' opera '; window.browser[' version ' = uamatch[1];} /** * Determine if the Safari browser/if (!uamatch) {uamatch = Useragent.match (/safari/([D.] +)/); if (uamatch!=null) {window.browser[' name '] = ' safari '; window.browser[' version ' = uamatch[1];} /** * Final Judgment is IE/if (!uamatch) {if (Useragent.match) (/msIE ([D.] +)/) {Uamatch = Useragent.match (/msie ([D.]!=null) +)/); window.browser[' name ' = ' IE '; window.browser[' version '] = uamatch[1]; }else{/** * IE10/if (Isie () &&!! Document.attachevent && (function () {' Use strict '; return!this} ()) {window.browser[' name '] = ' ie '; window.browser[' version ' = ' ten ';}/** * IE11/if (Isie () &&!document.atta chevent) {window.browser[' name '] = ' ie '; window.browser[' version ' = ' 11 ';}} }  /** * Registration Judgment Method */if (!$.isie) {$.extend ({isie:function () {return (Window.browser.name = = ' ie ');}});} if (!$.isch Rome) {$.extend ({ischrome:function () {return (Window.browser.name = = ' chrome ');});} if (!$.isfirefox) {$.extend ({ISFI Refox:function () {return (Window.browser.name = = ' Firefox ');}); } if (!$.isopera) {$.extend ({isopera:function () {return (Window.browser.name = = ' opera ');}};} if (!$.issafari) {$.exten D ({issafari:function () {return (Window.browser.name = = ' Safari ');}); }}) (JQuery, window, document);

How to use

1 2 3 Console.log (Window.browser); Console.log ($.isie ()); Console.log ($.ischrome ());
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.