Bruce Lawson’s personal site

HTML 5 Flash embedding and other validation errors

When I completed the first round of my HTML 5 redesign, some validation errors remained.

Most were due to WAI-ARIA roles being applied to new HTML 5 structural elements, which isn’t currently allowed (both specs are in draft, remmeber). I’m not worried about those; accessibility trumps validity for me, and ARIA doesn’t validate in HTML 4, either.

I was also getting an odd error with Remy Sharp’s groovy HTML 5 enabling script, which I’d surrounded by a conditional comment as only Internet Explorer needs it. Part of the JavaScript has a double hyphen and HTML 5 doesn’t like “--” in comments, so fearphage sent me a rewrite that reversed the JavaScript. You don’t need to do this as you would have the script in an external file; I have it included in the head of each page so that visitors can see what’s happening.

However, none of the embedded Flash movies from YouTube would validate. I was using the default code given by YouTube which nests an embed tag inside an object tag and which doesn’t validate in current flavours of (X)HTML because embed was never in any spec.

Fearphage suggested using just the object tag for the Flash movies, but Patrick Lauke pointed out that there are some problems with that approach:

One of the HTML 5 design principles is to “pave the cowpaths”. Because everybody uses embed, it’s been added to the spec. So by rearranging some of YouTube’s suggested code (self-closing param elements, escaping ampersands in URLs and repeating the URL for a third time as a data attribute on the object element) I came up with an accessible-as-possible, cross-browser, valid HTML 5 way to embed Flash movies:

<object width="425" height="344" data="http://www.youtube.com/v/8-pFwbHMuwA&amp;hl=en&amp;fs=1">
<param name="movie" value="http://www.youtube.com/v/8-pFwbHMuwA&amp;hl=en&amp;fs=1" />
<param name="allowFullScreen" value="true" />
<param name="allowscriptaccess" value="always" />
<embed src="http://www.youtube.com/v/8-pFwbHMuwA&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344" />
</object>

What we need now is for some kind soul to write a wizard that converts YouTube’s default code into code formatted as above.

It’s with some irony that I write this post, because one of the exciting things about HTML 5 is the video element that allows video to be added to a page with a simple <video src="blah.src" controls>I'm fallback content</video> and then plays it without any plugins or scripting. It allows an open, patent-free video codec to interact with canvas and SVG and it doesn’t require duplication of data twice or three times like the code contortions above.

Unfortunately it’s usefulness is mired in politics—see David Storey’s The future of video on the Web.

I’m too lazy to amend every instance from the last five years, but my home page is now valid apart from ARIA roles and an objection to the feed: protocol on a link to my RSS feed.

Thanks Patrick and fearphage.

18 Responses to “ HTML 5 Flash embedding and other validation errors ”

Comment by Remy Sharp

That IE conditional parsing error is superb! So it doesn’t like to encounter ‘–’ within the conditional. Brilliant! :-)

It’s worth noting that the JS snippet I wrote has an embedded IE sniff in the code, so it will only execute in IE. However, it’s a blanket IE sniff, so if IE8 implements HTML5 element support (or it might do already, I just missed it) the code will still run. But then, I guess IE will have a screaming fast JS engine – so it won’t matter anyway (…I wish/hope).

Comment by Bruce

Hi Philip, I didn’t give swfobject a go as I’m trying to make my site valid html5 that doesn’t rely on JavaScript.

What does it gain me that the approach I outline above doesn’t?

Comment by Bruce

Ah, I see. So SWFObject uses nested objects with some conditional comments, thereby getting round the fact that embed won’t validate in current flavours of (X)HTML.

I don’t need the conditional comments because embed works in HTML 5.

Comment by Bruce

Very nice Graham. Anyway it could escape the ampersands so it passes that validation, too?

Passing URL http://www.youtube.com/watch?v=BTk1JRbXdqU with 425 x 344 dimensions returns unecoded ampersands in the URLs.

(I looked at your source and it seemed to be trying to do that, so I’m stumped (being a PHP numpty).

What’s your license on that code?

Comment by Affan

Is there a way for the html5lib sanitization code to skip the object code for youtube so that we are able to sanitize the html input from the user but allow embedding of videos?

Leave a Reply

HTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> . To display code, manually escape it.