This article mainly introduces how to use native js to simulate jq to determine whether the current browser is ie, accurate to ie6 ~ 8. If you need it, you can refer to those who are familiar with jq and may occasionally use it to determine whether the current browser is ie or even the specific version of ie. For example, to determine that the current browser is ie7, the statement is as follows:
If ($. browser. msie & $. browser. version = 7) {// run the code for this region in ie7}
Native js, similar to jq writing, specific implementation code:
Script var browser = (function () {var isIE6 =/msie 6/I. test (navigator. userAgent); var isIE7 =/msie 7/I. test (navigator. userAgent); var isIE8 =/msie 8/I. test (navigator. userAgent); var isIE =/msie/I. test (navigator. userAgent); return {msie: isIE, version: function () {switch (true) {case isIE6: return 6; case isIE7: return 7; case isIE8: return 8 ;}} () };}) (); alert (browser. msie); alert (browser. version); script
You can customize the determination of firefox and chrome.