This post will discuss how to check if a user is using an IE browser with JavaScript.

Internet Explorer (IE) was once the most popular and widely used browser in the world, but it has been gradually losing its market share to other modern browsers, such as Chrome, Firefox, Safari, and Edge. IE is known for its poor performance, security issues, and lack of support for many web standards and features.

However, there are still some users who use IE for various reasons, such as legacy applications, corporate policies, or personal preferences. Therefore, as a web developer, we may encounter situations where we need to check if the user’s browser is IE or not, and perform some browser-specific code or actions accordingly. For example, we may want to display a warning message, redirect to another page, or enable or disable some features based on the browser detection.

1. Using document.documentMode property

The simplest method to check for IE browser with JavaScript is to use the window.document.documentMode property. This property is a unique feature of IE that returns the mode used by the browser to render the current document. The mode can be either a number that represents the compatibility mode version (such as 5, 7, 8, 9, 10, or 11), or undefined if the browser is not IE or is in standard mode. For example:

 
The documentMode returns the undefined value on all other browsers. For the Internet Explorer browser, it returns the IE mode used to render the document. It works with any version of IE that supports the window.document.documentMode property, which is IE 8 and above.

Another way to check for IE browser with JavaScript is to use the NavigatorID.userAgent property. This property returns the user agent of the browser, which is a string that identifies the browser name, version, platform, and other information. The navigator object is a global object that provides various methods and properties for working with the browser. To determine for the IE browser, we should check for MSIE or Trident in the user agent string. We can use a regular expression (RegEx) to match the user agent string with a pattern that matches IE browser.

 
Alternatively, we can use the String.prototype.includes() method or the String.prototype.indexOf() method to check if the user agent string contains “MSIE” or “Trident”, which are indicators of IE browser. Here is an example with the indexOf() method:

 
This method works with any version of IE that has a user agent string that contains “MSIE” or “Trident”, which are IE 6 and above. However, this approach is unreliable since users can modify the browser user agent string. Instead, we should use the document.documentMode property, which is IE-specific.

3. Using jQuery

To check for IE browser with jQuery, we can use feature detection, which checks if the browser supports certain features or functionalities. We can use the jQuery.support property, which contains a collection of properties that indicate the presence of different browser features or bugs. For example, we can use the following code:

Download Code

That’s all about checking for IE browser with JavaScript.