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;

✌️ Like this article? Follow me on Twitter and LinkedIn. You can also subscribe to RSS Feed.