Use JavaScript implementation to determine current browser _javascript tips

Source: Internet
Author: User

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.

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.