Javascript determines the IE version number

Source: Internet
Author: User

There are many ways to judge the version number of IE browser using js. I will introduce three related instances below. I recommend using the last concise version to judge IE browser. The most comprehensive method is the second.


In today's project, you need to determine the IE version number. Because jQuery 2.0 does not judge the browser version number (it recommends Feature Detection), you can see a piece of code written by a foreigner:

The Code is as follows: Copy code

Var _ IE = (function (){
Var v = 3, div = document. createElement ('div '), all = div. getElementsByTagName (' I ');
While (
Div. innerHTML = '<! -- [If gt IE '+ (++ v) +']> <I> </I> <! [Endif] --> ',
All [0]
);
Return v> 4? V: false;
}());

This code is really clever! Both introduction and backward compatibility! The general practice is: regular search USER_AGENT;
However, due to historical reasons, USER_AGENT has never been accurate and has been changed by major vendors.

 

For example:

IE10: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)

IE11: Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko


We strongly recommend the above Code!

A self-written

The Code is as follows: Copy code


<Span id = "Css"> </span>
<Script>
If (navigator. userAgent. indexOf ("MSIE")> 0)
{
// Whether the browser is Internet Explorer
If (navigator. userAgent. indexOf ("MSIE 6.0")> 0)
{
// 6.0 use 1.CSS
Css. innerHTML = '<link href = "1.css" rel =" stylesheet "type =" text/css ">'
}
If (navigator. userAgent. indexOf ("MSIE 7.0")> 0)
{
// 7.0 use 2.CSS
Css. innerHTML = '<link href = "2.css" rel =" stylesheet "type =" text/css ">'
}
} Else
{
// Otherwise, you can use 3.CSS and a specific browser. You can use navigator. userAgent to obtain information.
Css. innerHTML = '<link href = "3.css" rel =" stylesheet "type =" text/css ">'
}
</Script>

The following is a few recommended statements to determine the IE browser code.

The Code is as follows: Copy code

<Script type = 'text/javascript '>
Notie =-[1,];
If (-[1,]) {
// Standard browser code
} Else {
// Ie only code
}
</Script>

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.