how to detect Internet Explorer browser using JavaScript

published: 17 Aug 2022

2 min read

how to detect Internet Explorer browser using JavaScript

To detect whether the current browser is Internet Explorer, you can make use of the navigator.userAgent property.

The userAgent property returns the value of the user-agent header sent by the browser to the server. It contains information about the name, version, and platform of the browser.

The following example demonstrates how you can use navigator.userAgent to identify whether the current browser is Internet Explorer:

const isIE = () => {
    const ua = navigator.userAgent;
    return ua.indexOf('MSIE') > -1 || ua.indexOf('Trident') > -1;
};

Alternatively, you could also use the document.documentMode property. It only works in IE 5-11 and returns an integer indicating the mode used by the IE browser to render the current document:

const isIE = !!document.documentMode;

how to detect Internet Explorer browser using JavaScript | Coding Tips And Tricks

Are we missing something?  Help us improve this article. Reach out to us.

Are you looking for other code tips?

Check out what's on in the category: javascript, programming
Check out what's on in the tag: javascript, programming