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
;(function ($, window, document,undefined) {if (!window.browser) {var useragent = Navigator.userAgent.toLowerCa
Se (), uamatch;
Window.browser = {}/** * to determine if the IE/function Isie () {return ("ActiveXObject" in window); /** * Determine if Google browser/if (!uamatch) {uamatch = Useragent.match/chrome\/([\d.]
+)/);
if (uamatch!=null) {window.browser[' name '] = ' chrome ';
window.browser[' version '] = uamatch[1]; }/** * To determine if it is Firefox browser/if (!uamatch) {uamatch = Useragent.match (/firefox\/.]
+)/);
if (uamatch!=null) {window.browser[' name '] = ' Firefox ';
window.browser[' version '] = uamatch[1]; }/** * Determines whether Opera browser/if (!uamatch) {uamatch = Useragent.match (/opera. [\d.]
+)/);
if (uamatch!=null) {window.browser[' name '] = ' opera ';
window.browser[' version '] = uamatch[1]; }/** * To determine if safari bangsThe Navigator/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 ' = ' 10 '; }/** * IE11/if (Isie () &&!document.attachevent) {window.browser[' n
Ame '] = ' ie ';
window.browser[' Version ' = ' 11 '; /** * Registration Judgment Method/if (!$.isie) {$.extend {isie:function () {
return (Window.browser.name = = ' ie ');
}
});
} if (!$.ischrome) {$.extend ({ischrome:function () {return (Window.browser.name = = ' chrome ');
}
}); } if (!$.isfirefox) {$.extend ({isfirefox:function () {return (Window.browser.name = = ' Firefox ')
;
}
});
} if (!$.isopera) {$.extend ({isopera:function () {return (Window.browser.name = = ' opera ');
}
});
} if (!$.issafari) {$.extend ({issafari:function () {return (Window.browser.name = = ' Safari ');
}
});
}}) (JQuery, window, document);
How to use
Console.log (window.browser);
Console.log ($.isie ());
Console.log ($.ischrome ());
The above mentioned is the entire content of this article, I hope you can enjoy.