Native js imitates jq to determine whether the current browser is ie, accurate to ie6 ~ 8_javascript skills

Source: Internet
Author: User
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.

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.