How to Develop a Web Application Compatible With Internet Explorer 11
Though IE is now deprecated, people out there still use it. Learn how to tailor your HTML and CSS to create IE compatible apps and UIs.
Join the DZone community and get the full member experience.
Join For Free
Developing web pages compatible with Internet Explorer can be tough at times. Even though Internet Explorer’s support was pulled back by Microsoft, it still remains a popular choice among users. Internet Explorer misbehaves with some of the most important components of HTML, be it low-height, margin, or padding.
To achieve a proper fix to this problem, developers can use conditional comments and CSS commands to target browser specific commands. While it is practically impossible to achieve 100% compatibility for Internet Explorer due to its discontinued support and compatibility issues, there are several feasible ways to make sure that the user receives a decent experience. Although there is no way to develop perfectly compatible web pages, here’s a guide on how to develop a web application compatible with Internet Explorer 11 and its other variants.
1. Using Conditional Comments
Conditional statements are the best possible way to target a piece of code specific to a given browser. They make sure that the code targets the mentioned browser and doesn’t interfere with the existing code. Other browsers ignore these kinds of HTML chunks. Conditional statements have become a standard method for embedding extra CSS into the web sheet to fill the voids in such browser’s incapabilities. For instance, incorporating the following code in your browser HTML with the source
<link href="everything.css" rel="stylesheet">
<!--[if IE]>
<link href="stupidie.css" rel="stylesheet">
<![endif]-->
will only work for Internet Explorer (IE 9 or below). So, this will behave as a comment for all other browsers except Internet Explorer. You can also code this for specific IE versions by mentioning the exact version. This saves time that you’d have wasted in creating a completely new stylesheet for Internet Explorer. In addition to this, conditional comments don’t require DHTML or scripting, thus eliminating the need for a scripting engine, too. Conditional comments are brought into action only during the parsing and downloading phase, so only the content earmarked for the browser is actually downloaded.
2. Do Not Skip Cross-Browser Testing
What seems to be beautiful code in your personal browser might misbehave in other browsers. No matter how good your code is, there’s always a possibility that there’s something that doesn’t work in another browser. This is the core reason why you should not upload website to the server without performing cross-browser testing.
Opting for online tools that you access to multiople browsers, so you never have to worry about missing out on a popular browser and OS combination. Use the tool to perform live and interactive cross-browser testing of your public or locally hosted web pages and applications. You may use the tool to capture automated screenshots for accelerated web layout testing. There are a lot of other amazing online cross-browser testing tools. Check them out before proceeding with the testing process.
3. Using Certain CSS Commands
Internet Explorer and its newer sibling, Edge, hold a considerable share of audience. So, it is important to account for the compatibility of your web pages for IE and Edge users. Every browser behaves differently and this is the reason why checking the cross-browser compatibility of HTML pages and other pieces of code are in demand. Here are some of the most useful CSS commands that you can use for higher compatibility with IE and edge:
a. Vanishing Background Images and Text
Internet Explorer can sometimes make the background images and text disappear, enclosed by floating elements, especially during page scrolls. To tackle this problem, you can use the CSS command position: relative
in the CSS rules that apply to the background image.
b. Unstyled Version of the Page Flashing
Once in a while when the site is stacking, an unstyled form of the page may show up for a second or two, preceding the loading of the outer CSS template. This is an instance of a Flash of Unstyled Content (FOUC). Although it corrects itself once the styles are loaded, this bug can be painstaking and confusing.
c. Doubling of the Margin Attribute
Time and again in IE, the margin attributes can double, for example, and a specified margin of 10px to a floating element winds up taking up to 20px. This bug is called the double margin bug and is quite consistent in IE6. The bug can be fixed by applying the display: inline
rule to the CSS floating element.
d. Dropping of Some Containers
With only partial support for height and width properties by Internet Explorer, a bug called the ‘Flat Drop Bug’ often appears. The containers grow out of their assigned sizes, thus creating havoc on the page. Style your boxes with a negative right margin to prevent this. Apart from that, incorporate a position: relative
statement in your code.
e. Min-Height Property
IE has this bad habit of ignoring the min-height
property. It fetches the one from the declare minimum height, which results in some compatibility issues. Use the following statement in your code to fix the issue:
#inner-container {
min-height: 140px;
height: auto !important;
height: 140px;
}
4. Some JavaScript Hacks
Although IE is trying hard to cope up with the modern day browsers, it is still popular among developing countries and that’s why it is important that your HTML supports IE well. Apart from the recommendations above, there is one more CSS hack to achieve a web application compatible with Internet Explorer 11.
* Flickering Background Images
Background images can sometimes be wobbly when CSS is being utilised for buttons and links. This happens because the IE browser fails to cache the background images and thus keeps on reloading. You can solve this bug by adding the following code:
try {
document.execCommand('BackgroundImageCache', false,true true);
}
catch(e) {}
The purpose of this article is to show you how to develop a web application compatible with Internet Explorer 11 and lower. We have discussed some of the most prominent issues and their fixes. However, you can’t just rely on your code to work perfectly for all browsers and you must always test your web pages for cross-browser compatibility.
There are plenty of tools available to make sure that your pages look like you actually want them to be. The core requirement is to make sure that all the issues with your web page are resolved and there is nothing that doesn’t work well on any Internet Explorer browser. Last but not the least, Enterprise Mode for Internet Explorer 11 can be exceptionally compelling in giving backward compatibility. The Enterprise Mode Site List incorporates the capacity to put any web application in any document mode, including IE8 and IE7 Enterprise Modes, without even changing a single line of code.
Opinions expressed by DZone contributors are their own.
Comments