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;
Are we missing something? Help us improve this article. Reach out to us.
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;
Are you looking for other code tips?
JS Nooby
Javascript connoisseur