In a seminal article titled How to get HTML5 working in IE and Firefox 2 is mentioned a JavaScript technique to make Internet Explorer 8 (and lower) recognize the various HTML5 elements. This script simply creates all HTML5 elements by using the createElement()
method, thus allowing IE to correctly insert these elements into its DOM structure and stylize them. It works very smoothly: first, it checks if conditional comments are enabled by performing the following routine:
if(!/*@cc_on!@*/0)return;
In this script, everything is wrapped within a self-executing function. After the first check, the variable e
will be created. This variable is a comma-separated string containing the names of all HTML5 elements. With the aid of the split()
method, e
is later turned into an array. Using a for
loop on this array, the script invokes the createElement()
method on each element of the array.
The script must be placed within conditional comments, like so:
<head> <!--[if lte IE 8]> <script type="text/javascript" src="html5.js"></script> <![endif]--> </head>
You can download this script here.