Fixing the Internet Explorer nesting issue

As we saw in session 4, there is a bug in IE6's treatment of nested <object>s. We need to find a pragmatic solution to the problem which meets our basic engineering criteria - namely, full XHTML compliance and browser independence.

Internet Explorer conditional comments

The basic structure of XHTML comments is:

<!--   comment goes here  -->

Internet Explorer understands specially formatted comments which allow for the inclusion or exclusion of code, depending on the browser. The following code shows how code can be shown to other browsers, but IE will ignore it:

<!--[if !IE]>-->
   <p>do something</p> 
<!--<![endif]-->

The code above passes the XHTML validation test and only relies upon the ability of Internet Explorer to understand these special comments. Browsers that don't understand the comments will use the code anyway, as it will just see two comment lines. Using this technique we can solve the nesting problem as follows:

<!--[if !IE]>-->
<object type="video/x-ms-wmv" 
        data="../session2/resources/IceScraping.WMV"
        width="320" height="260">
  <param name="src"
         value="../session2/resources/IceScraping.WMV" />
  <param name="autoplay" value="0" />
  <param name="showcontrols" value="1" />
<!--<![endif]-->
  <object classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
          codebase="http://acti ... #Version=5,1,52,701" 
          standby="Loading Media Player components..." 
          type="application/x-oleobject"
          width="320" height="260">
    <param name="ShowDisplay" value="0" />
    <param name="ShowControls" value="1" />
    <param name="AutoStart" value="-1" />
    <param name="AutoSize" value="0" />
    <param name="FileName"
           value="../session2/resources/IceScraping.wmv" />
    <p>Cannot play WMV files!</p>
  </object>
<!--[if !IE]>-->
</object>
<!--<![endif]-->

The conditional comments remove the outer <object> if the browser is Internet Explorer. That way Internet Explorer only sees the ActiveX version. Other browsers will use the outer <object> providing it can use it. If not the inner <object> will be processed - and potentially fail - and finally fall back to the inner code. In this case there is a simple text message, but a suitable fallback for embedded content might be an image with a caption.

The effect of this code is shown below:

Cannot play WMV files!

Valid XHTML 1.0! | Valid CSS! | WCAG Approved AA
Page design by: John P Scott - Hosting with: Netcetera