views:

133

answers:

2

A typical code fragment obtained from the YouTube embed feature looks like this:

<object width="660" height="405">
  <param name="movie" value="http://www.youtube.com/v/NWHfY_lvKIQ?fs=1&amp;amp;hl=en_GB&amp;amp;border=1"&gt;&lt;/param&gt;
  <param name="allowFullScreen" value="true"></param>
  <param name="allowscriptaccess" value="always"></param>
  <embed src="http://www.youtube.com/v/NWHfY_lvKIQ?fs=1&amp;amp;hl=en_GB&amp;amp;border=1"
         type="application/x-shockwave-flash" 
         allowscriptaccess="always" 
         allowfullscreen="true" 
         width="660" 
         height="405">
  </embed>
</object>

Now, the <embed> element has a type attribute to tell the browser it is embedding a flash file, but for browsers using the <object> tag, there appears to be no information available to the browser!

Why is a classid or codebase attribute not required here? The only options I can think of are:

  • IE assumes Flash embedding in the absence of other information
  • or, IE reads this information from the <embed> tag

I can't find documentation to verify either option. And I'm curious!

EDIT: found a great comparison of Flash embedding techniques here. Still want to know how it works though...

+1  A: 

I experimented a bit and found that removing the <embed> tag causes IE to fail to embed the video. I was surprised that IE used the embed tag, so delved deeper. If you just want to know the answer, scroll down the 'summary' at the end!

The simplest thing which worked in IE8 is this:

<embed src="http://www.youtube.com/v/NWHfY_lvKIQ?fs=1&amp;amp;hl=en_GB&amp;amp;border=1"
         width="660"
         height="405">
 </embed>

No type attribute there, so the browser must be checking the MIME type of the src attribute to figure out what to do. I verified this by serving a Flash file with a different MIME type - it would not play unless I provided a type attribute of application/x-shockwave-flash (this behaviour is documented for IE here)

Of course, if an <object> tag does contain the classid, the <embed> will be ignored, which is what you'd expect. I verified this by having the embed tag reference another video

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="660" HEIGHT="405" id="adobeWay">
<PARAM NAME=movie VALUE="http://www.youtube.com/v/NWHfY_lvKIQ?fs=1&amp;amp;hl=en_GB&amp;amp;border=1"&gt;
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#FFFFFF>

<embed src="http://youtube.com/v/rIFh1ydXWmg"
         type="application/x-shockwave-flash"
         allowscriptaccess="always"
         allowfullscreen="true"
         width="660"
         height="405">
  </embed>

</OBJECT>

When the object tag is used, the Flash plugin doesn't care what the MIME type of the movie is. Again, I verified this by serving a valid SWF file with a different MIME type.

Remove the classid from that last test, and you'd get the alternative video in the <embed> tag. This leads me to wonder why there's any <param> tags at all if they are just being ignored in a YouTube-style embed.

Summary

When there's no classid attribute in an <object> (or any other way of determining the required plugin, like a data attribute), IE renders whatever it can find inside the object tag, which means it will render the <embed> tag (IE calls this object fallback). If that tag contains no type attribute, then the MIME type of the src is used to determine the correct plugin to use.

Paul Dixon
A: 

It's the MIME type. This is sent by the server to help the browser identify the type of content. MIME types are associated with helper plugins.

Delan Azabani
I realised it might be the MIME type, but that information is available *only* if IE is looking at the `<embed>` tag, which was a surprise.
Paul Dixon
IE's implementation has always been iffy.
Delan Azabani
As it turns out, it's entirely by design. See the link to 'object fallback' in my answer.
Paul Dixon
You are saying that IE only uses `object` if it has a `classid`, otherwise it fails, and renders what's inside instead (usually an `embed`, which is nonstandard too). This is incorrect implementation. `object` should determine the plugin based on the MIME automatically.
Delan Azabani
yes, but in this case, the object can't - it's not been given a data attribute so there's nothing for it to fetch and analyse.
Paul Dixon