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:
- Internet Explorer can’t stream videos but must download the full movie before showing it
- screenreaders can’t access accessibility information within the Flash movie (admittedly not likely to be a problem with most YouTube uploads)
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&hl=en&fs=1">
<param name="movie" value="http://www.youtube.com/v/8-pFwbHMuwA&hl=en&fs=1" />
<param name="allowFullScreen" value="true" />
<param name="allowscriptaccess" value="always" />
<embed src="http://www.youtube.com/v/8-pFwbHMuwA&hl=en&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.
28 Responses to “ HTML 5 Flash embedding and other validation errors ”
You don’t mention the often popular Flash Satay method that some of the kids like to use. Notwithstanding JAWS not properly reading Satay’d objects, will the Satay validate if used?
Just curious: Did you give swfobject a go? I recently posed the question about HTML 5 on the swfobject google group (I even mentioned your site), and it would be great if you can share any experiences with swfobject and HTML 5.
http://groups.google.com/group/swfobject/browse_thread/thread/3ad1ece8aef0f9c9
Cheers
- philip
SWFObject has two approaches, one is JavaScript (‘dynamic publishing’), the other is plain markup (‘static publishing’, which uses a nested object).
Try it out: http://pipwerks.com/lab/swfobject/basics/2.0/index.html
Official documentation:
http://code.google.com/p/swfobject/wiki/documentation
How about Hixie’s nested object method?
I managed to use it for a YouTube video I posted once and it both plays and my page validates as XHTML 1 strict.
Ah, time to answer my own question, as you’ve said above. I forgot that the method used conditional comments.
Carry on, ignore me!
So, what’s the best method of embedding flash that will keep JAWS happy?
thanks,
Joe
[...] Fehler sind ausgemerzt. Hierzu möchte ich auf einen Link hinweisen, der kurz eklärt, wie man Einbettungen fĂĽr HTML5 anpassen kann. Sollten dann noch Fehler im Validator erscheinen, sind es Schönheitsfehler – basta. [...]
Great post Bruce (yes, it was a while ago I know). Don’t know if the following helps:
http://www.irwinassociates.eu/movie-code.zip
and a usable version at
http://www.irwinassociates.eu/movie-code.php
Could do with some tarting up…
Thanks Bruce. The revised code should do the trick, I think. The textarea could probably do with expanding too.
Code is simply free.
Is JAWS happy with just an embed without a wrapping object?
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?
I thought I’d convert my website to HTML5 and use this method for embedding my Flash movies. All went well except it didn’t display the movies in any version of IE (using IETester)…
Could have something to do with my not including the shim… Der!
Hi Bruce. I was wondering if there was any benefit to using the OBJECT element at all, here. What happens if you only use EMBED? Do browsers understand that allright? Are JAWS and NVDA, using either IE or Firefox, happy?
The advantage of the OBJECT element over EMBED used to be:
- can be used for lots of formats (plugin data, HTML pages, images, multimedia files to be played by the browser);
- allows rich alternative content (much better than the limited alt attribute of IMG and AREA elements);
- valid HTML4/XHTML1.
In HTML5, EMBED validity is not an issue, and versatile nature of OBJECT was shot down by the blessing of IFRAME, and the addition of VIDEO and AUDIO elements. (I’m not lamenting that, mind you. OBJECT was a great idea, but the spec was probably too vague for it to gain traction. The HTML world has moved on and now we have a specific element for each media category, let’s roll with that.) So the only remaining virtue of OBJECT over EMBED is (rich) alternative content. Since we’re using EMBED as the only alternative content anyway, this advantage is lost too. So why use OBJECT at all if, by chance, browser and screen reader support lets us drop it?
Anybody knows what the support for EMBED is these days?
[...] might also want to read about Bruce “Awesome” Lawson’s getting video validated in HTML5. Tags: video, W3C ← 腾讯科技专访 Yay, HTML5 ContentEditable! [...]
[...] One lingering problem is that the <object> code recommended in the niftyPlayer documentation fails HTML5 validation. HTML5 actually supports both <object> and (for the first time ever in an HTML spec) <embed>. However, the classid and codebase attributes are obsolete, and probably a few other attributes as well. At this phase in my testing I wasn’t especially inclined to spend much time trying to figure out how to convert old <object> code to valid, functional HTML5, although it looks like Bruce Lawson has gotten a jump start on this in his article HTML 5 Flash embedded and other validation errors. [...]
The embed tag doesn’t work in older versions of IE period, and html5 is also not supported by older browsers. Although I agree that we should all be using the latest and greatest, it’s not always the case. For example there are some embedded (not to be confused with our html tag) browsers that are stuck at version x and cannot be updated (lets assume that the flash works of course).
So to keep code clean and have it degrade nicely, you can display flash in a single object tag no matter what browser you use as follows (Note the type attribute, it’s what makes this not need the embed tag):
<object width=”425″ height=”344″ type=”application/x-shockwave-flash” data=”http://www.youtube.com/v/8-pFwbHMuwA&hl=en&fs=1″ id=”youtubevideo” >
<param name=”allowFullScreen” value=”true” />
<param name=”allowscriptaccess” value=”always” />
<param name=”movie” value=”http://www.youtube.com/v/8-pFwbHMuwA&hl=en&fs=1″ />
</object>
No more embed tag, only 2 urls (and only since IE doesn’t like having the “movie” param omitted) and xhtml and html5 compliant.
I hope this might be the piece of mind someone’s looking for.
This is the perfect HTML5 flash embed code which will work in all browsers including IE but IE8 or higher.
Happy coding..
cheers
Thanks for this post. Been looking for the embed script for html5.
this script really helped
I believe what you published made a lot of sense. But, think on this, what if you typed a
catchier title? I am not saying your information is not solid, however suppose you
added a title that makes people want more? I mean Bruce
Lawson’s personal site : HTML 5 Flash embedding and other validation errors
is a little boring. You might look at Yahoo’s front page and see how they create news titles to grab people to click. You might add a video or a related pic or two to get readers excited about everything’ve written.
In my opinion, it could bring your website a little livelier.
This article will assist the internet visitors for building up new weblog or even a
blog from start to end.
Here is my homepage; air quality testing
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).