Reports of broken sites are an important part of the feedback the IE team receives from the community. When we receive a report of a broken site, we take it and identify the core issue causing the problem. A number of these issues end up being side effects of changes we deliberately made in IE8, but even these are useful. They help us identify which IE8 changes have the broadest compatibility impact. In this post I'll share some of these issues with you so you can quickly identify problems affecting your site when migrating from IE7 to IE8.
Differences between IE8 Compatibility View and IE7
We strive to make Compatibility View behave as much like IE7 as possible, but we do make exceptions. Many of these exceptions enable improved security and accessibility features immediately, even for sites that have not yet migrated to IE8 Standards Mode.
Cross Document Communication
Extending the Event Object
event.source = myObject; // Read-only in IE8
event.mySource = myObject;
Attribute Ordering
attr = elm.attributes[1]; // May differ in IE8
attr = elm.attributes["id"];
Setting Unsupported CSS Values
try { elm.style.display = "table-cell"; } catch(e) { // This executes in IE7, // but not IE8, regardless of mode }
Differences Between IE8 Standards Mode and IE8 Compatibility View
We see the majority of compatibility issues in IE8 Standards Mode. Most of these occur when sites expect legacy behavior that no longer exists in IE8 Standards Mode. Upgrading your site to run in IE8 Standards Mode is the best option in the long run, but in the interim you can quickly fix these types of issues by running your site in Compatibility Mode. This is described in Jefferson's post on the EmulateIE7 meta tag. In addition to the issues mentioned above, here's what you should be aware of.
Version Detection
<!--[if IE]> <link rel="stylesheet" type="text/css" src="ie.css" /> <![endif]-->
<!--[if lte IE 7]> <link rel="stylesheet" type="text/css" src="ie.css" /> <![endif]-->
Object Detection
if(window.postMessage) { window.addEventListener( "load", myHandler, false ); }
if(window.addEventListener) { window.addEventListener( "load", myHandler, false ); }
Malformed HTML
<ul> <li>1.1 <ul> <li>1.1.1</li> </li> <!-- Closes 1.1 in IE8, but not IE7 --> <li>1.1.2</li> </ul> </li> </ul>
<ul> <li>1.1 <ul> <li>1.1.1</li> <!-- </li> --> <li>1.1.2</li> </ul> </li> </ul>
Working with an Element’s Class
return elm.getAttribute("className");
return elm.getAttribute("class");
GetElementById
<div id="Test"></div> <script type="text/javascript"> // No element is found because of case difference var test = document.getElementById("test"); </script>
<div id="Test"></div> <script type="text/javascript"> // Element Test is found var test = document.getElementById("Test") </script>
Generic CSS Prefix Selectors
v\:* { behavior: url(#default#VML); }
v\:polyline, v\:line { behavior: url(#default#VML); }
CSS Expressions
/* CSS */ #main { background-color: expression( (new Date()).getHours()%2 ? "#000" : "#fff" ); }
/* Script */ var elm = document.getElementById("main"); if((new Date()).getHours()%2) { elm.style.backgroundColor = "#000"; } else { elm.style.backgroundColor = "#fff"; }
Native JSON Object
if(!window.JSON) JSON = myJSON; JSON.encode(obj); // Not part of the standard
JSON = myJSON; JSON.encode(obj);
Initial CSS Property Values
var zIndex = elm.currentStyle.zIndex; if(zIndex == 0) { // custom code }
var zIndex = elm.currentStyle.zIndex; if(zIndex == 0 || zIndex == "auto") { // custom code }
Unspecified CSS Property Values
var zIndex = elm.style.zIndex; if(zIndex === 0) { // custom code }
var zIndex = elm.style.zIndex; if(zIndex === 0 || zIndex === "") { // custom code }
Attributes Collection
var attr = elm.attributes["checked"]; // Potential script error in IE8 return attr.specified;
var attr = elm.attributes["checked"]; if(attr) return attr.specified; else return false;
That's all I have for now. If you encounter anything else you feel should be on the list, please add it to the comments to help others out.
Tony Ross Program Manager
Update 3/13/09: Corrected code samples under version detection section.