Js judgment ie Method collection (including regular expressions) code short classic [original] _ javascript skills

Source: Internet
Author: User
Javascript checks whether it is ie or a specific version. There are many methods and whether the regular code comparison section is Opera:

Script is_opera =/opera/I. test (navigator. userAgent); alert (is_opera); script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]


Whether it is IE:

Script is_opera =/opera/I. test (navigator. userAgent); var is_ie = (/msie/I. test (navigator. userAgent )&&! Is_opera) alert (is_ie); script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]


Whether it is ie7:

The Code is as follows:


Script
(Is_ie &/msie 7 \. 0/I. test (navigator. userAgent ));
Script


Script var isIe =/msie/I. test (navigator. userAgent); alert (isIe); script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]


Script if (document. uniqueID) {alert ("the script runs in IE browser! ");} Else {alert (" the script runs in a non-IE browser! ");} Script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]



Determine the ie version using javascript

Script function Browser () {var ua, s, I; this. isIE = false; // Internet Explorer this. isNS = false; // Netscape this. version = null; ua = navigator. userAgent; s = "MSIE"; if (I = ua. indexOf (s)> = 0) {this. isIE = true; this. version = parseFloat (ua. substr (I + s. length); return;} s = "Netscape6/"; if (I = ua. indexOf (s)> = 0) {this. isNS = true; this. version = parseFloat (ua. substr (I + s. length); return;} // Treat any other "Gecko" browser as NS 6.1. s = "Gecko"; if (I = ua. indexOf (s)> = 0) {this. isNS = true; this. version = 6.1; return ;}}var browser = new Browser (); alert (browser); script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

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.