Embedding YouTube Video with iPhone Fallback
Just a quick note as a reminder to myself how to embed YouTube videos in a standards compliant, valid XHTML syntax. It works across all current browsers, doesn’t use <embed>, and has the elegant fallback displaying a still image that is linked to YouTube, thus enabling iPhone users without Flash to view the video.
<object type="application/x-shockwave-flash" data="http://www.youtube.com/ v/ VideoID" width="480" height="360"><param name="movie" value="http://www.youtube.com/ v/ VideoID" /><param name="quality" value="high" /><param name="allowFullScreen" value="true" /><!-- Fallback content --><a href="http://www.youtube.com/ watch? v=VideoID"><img src="http://img.youtube.com/ vi/ VideoID/0.jpg" width="480" height="360" alt="[Video title]" />
YouTube Video</a></object>
Please note that there are spaces in the code above to allow linebreaks. If you copy and paste you need to remove those.
Here is an example:
Standards compliant, iPhone compatible embedding of a YouTube video http://learningtheworld.eu/2009/youtube-embed/ (via @kliehm)
This comment was originally posted on Twitter
Embedding YouTube Video with iPhone Fallback http://bit.ly/8n1oLU
This comment was originally posted on Twitter
Neat post by @kliehm on embedding youtube video with iphone fallback http://is.gd/55ccl
This comment was originally posted on Twitter
Thanks for the code @kliehm!
It works very well, thanks so much.
Two questions re: the user experience:
Thanks, Mark
Hi Mark, I’ve been thinking about the “play” symbol, too, but I believe the easiest and most compatible way would be an overlay with an image. On the other hand we’re talking about highly advanced browsers, so I guess something could be constructed with CSS3. Anybody up for the challenge?
Concerning your second question I don’t think there’s a way to return to the browser if we implement just a link. In that case the link opens in the YouTube App, and there’s no way back. An alternative and even sexier approach would be native HTML5 video support. Alas I don’t think the API already features that.