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&hl=en_GB&border=1"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/NWHfY_lvKIQ?fs=1&hl=en_GB&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…
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:
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 videoWhen 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
classidattribute 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 notypeattribute, then the MIME type of thesrcis used to determine the correct plugin to use.