The Most Secure Cross Browser Testing Platform since 2012

Make Your Website Microsoft Edge Ready

BLOG / BrowseEmAll / BrowserNews / Browsers / Multibrowser / Tips / Web Development

Make Your Website Microsoft Edge Ready

Web browsers today have evolved far beyond being mere tools for accessing the internet; they have become powerful platforms that directly shape user experiences. Microsoft Edge, with its Chromium-based architecture, stands out as a fast, secure, and user-friendly browser that fully supports modern web standards, playing a leading role in this transformation. For web developers, this means not only ensuring browser compatibility but also leveraging the innovative features Edge offers to optimize their websites. In this article, we’ll explore how to test your website for Microsoft Edge compatibility, address common issues, and align your site with modern web standards.

X-UA-Compatible

Some websites rely on the X-UA-Compatible meta tag to ensure compatibility with older versions of Internet Explorer. However, since Microsoft Edge does not support this tag, it can cause the website to render incorrectly. To resolve this issue, you should remove the X-UA-Compatible meta tag and update your page to comply with modern HTML5 standards. This will ensure compatibility with both Edge and other modern browsers.

Older browsers, particularly earlier versions of Internet Explorer, use the X-UA-Compatible meta tag to force the page to run in a specific rendering mode. However, this code can create incompatibility with modern browsers.

<meta http-equiv="X-UA-Compatible" content="IE=8">

Modern browsers naturally support HTML5 standards and up-to-date web technologies. Such a meta tag is no longer necessary, and you can simplify your code by adopting a modern structure.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Modern Browser Support</title>
</head>
<body>
  <p>Welcome to a modern web experience!</p>
</body>
</html>

User Agent String Detection Issues

Microsoft Edge’s User Agent String is now Chromium-based and can be detected as Google Chrome or Safari. This change may cause older code to fail in accurately identifying the browser, leading to potential compatibility issues. To address this, prioritize feature detection over browser detection, as this approach is more robust and future-proof. If browser detection is unavoidable, update your older code to recognize the new User Agent String format used by Microsoft Edge.

The Absence of the attachEvent and removeEvent APIs

Microsoft Edge no longer supports the attachEvent and removeEvent methods previously used in Internet Explorer, which can cause older JavaScript code to break. To resolve this issue, replace these outdated methods with the modern addEventListener and removeEventListener APIs, which are supported by all modern browsers. If you need to maintain compatibility with older browsers, consider using a polyfill to bridge the gap and ensure consistent functionality.

Older versions of Internet Explorer used methods such as attachEvent to attach event listeners and detachEvent to remove them. These methods were specific to Internet Explorer and did not support modern web standards.

button.attachEvent("onclick", function() {
  alert("Button clicked!");
});

This code only works in Internet Explorer and is not supported in other modern browsers.

Modern browsers use the standardized and more robust addEventListener and removeEventListener APIs. These APIs are not browser specific and are compatible with all modern browsers.

button.addEventListener("click", function() {
  alert("Button clicked!");
});

This code works in all modern browsers including Edge, Chrome, Firefox, and Safari.

Removal of currentStyle API

The currentStyle API, which was used in IE-based browsers, is no longer supported in Microsoft Edge. This can cause issues for older code that tries to access CSS style information. To resolve this, replace currentStyle with the modern and standardized getComputedStyle() method, which is supported by all modern browsers and provides a reliable way to retrieve computed style values.

Usage of currentStyle

var element = document.getElementById("myElement");
var style = element.currentStyle;
console.log(style.backgroundColor);

Using getComputedStyle

var element = document.getElementById("myElement");
var style = window.getComputedStyle(element);
console.log(style.backgroundColor);

This updated code works correctly in modern browsers and eliminates the use of currentStyle.

Conditional Comments

Conditional comments specific to Internet Explorer are not supported by Microsoft Edge. This can cause code written for older versions of IE to become inactive in Edge, leading to compatibility issues. To resolve this, you should remove the old code within conditional comments or update it to be compatible with Edge. With modern CSS and JavaScript techniques, you can achieve cross-browser compatibility without relying on conditional comments. This transition will help you maintain a cleaner and more sustainable codebase.