Dynamic Web Lab

Best Ways to Detect Internet Explorer (IE) Browser

  • April 10, 2013
  • CSS

Best Ways to Detect Internet Explorer (IE) Browser

Although Internet Explorer (IE) has officially reached the end of its life, many developers still need to detect and handle IE-specific behavior—especially when supporting legacy systems or users on outdated infrastructure. Detecting IE reliably allows you to apply fallbacks, display warnings, or gracefully degrade unsupported features.

In this blog post, we’ll explore the best methods to detect Internet Explorer, both client-side and server-side, along with tips and best practices for maintaining compatibility.


Why Detect Internet Explorer?

Even though Microsoft Edge has replaced IE, the need for Internet Explorer detection still arises in cases like:

• Supporting internal enterprise tools using legacy tech.

• Ensuring graceful degradation for unsupported features (e.g., CSS Grid, ES6).

• Displaying browser upgrade warnings to encourage users to switch.

• Preventing rendering bugs due to IE’s outdated rendering engine.


Method 1: Detect IE Using JavaScript (User Agent)

The most common method is by checking the browser’s user agent string:

function isIE() {
  return /MSIE|Trident/.test(window.navigator.userAgent);
}

if (isIE()) {
  alert("You are using Internet Explorer. Please upgrade your browser.");
}Code language: JavaScript (javascript)

Pros:

• Simple and widely supported.

• Quick to implement.

Cons:

• User agent strings can be spoofed.

• May not work reliably in the future.


Method 2: Use document.documentMode

This is a more reliable method, as documentMode is unique to IE:

function isIE() {
  return !!document.documentMode;
}Code language: JavaScript (javascript)

If the browser returns a value for documentMode, it’s definitely IE.

Pros:

• Highly accurate.

• Less prone to spoofing than user agent detection.

Cons:

• Only works in the browser (not server-side).


Method 3: Use Conditional Comments (HTML-based, IE only)

Conditional comments were an IE-specific feature, supported in IE 5–9.

<!--[if IE]>
  <p>You are using Internet Explorer.</p>
<![endif]-->Code language: HTML, XML (xml)

Pros:

• Very accurate for older versions of IE.

Cons:

• Only works up to IE 9.

• Deprecated in modern browsers.


Method 4: CSS Hacks for IE

You can target IE using unique CSS selectors or hacks:

/* IE 10+ */
_:-ms-lang(x), _:-webkit-full-screen, body {
  background: red;
}Code language: CSS (css)

Or use media query hacks:

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
  /* IE10+ specific styles */
}Code language: CSS (css)

Pros:

• Useful for applying IE-specific CSS fixes.

Cons:

• Not suitable for detection in JavaScript.

• Can become brittle or hard to maintain.


Method 5: Server-Side Detection (PHP Example)

For backend detection, you can parse the User-Agent header:

function isIE() {
  return preg_match('/MSIE|Trident/', $_SERVER['HTTP_USER_AGENT']);
}Code language: PHP (php)

Pros:

• Useful for redirecting users or serving different content.

Cons:

• Less flexible than client-side detection.

• User-Agent can still be spoofed.


Best Practice: Notify and Educate

Instead of only detecting IE, it’s often helpful to inform users with a custom message or redirect:

if (isIE()) {
  window.location.href = "/unsupported-browser.html";
}Code language: JavaScript (javascript)

Create a dedicated page that explains:

• Why the site may not work properly in IE.

• Which modern browsers to switch to.

• How to upgrade or get help.


Although Internet Explorer is largely obsolete, detecting it remains necessary in specific environments. Whether you’re building for enterprise apps or want to provide users with upgrade guidance, using one or a combination of these detection methods will help you manage IE gracefully.

Written by

Maidul Islam

I am a freelance web developer.Like to share what i learn.