Making YouTube Videos XHTML Valid

Filed under: Asides | Tags: code, XHTML valid | July 15th, 2010
Post

Sometime ago I found that my sight wasn’t XHTML valid. The problem was that YouTube video embed code is not XHTML valid. A search led me to this sight. It is easier than it looks. You just remove unnecessary code and rearrange what is left.

This is what you get from YouTube:

<object width="640" height="385"><param name="movie" value=
"http://www.youtube.com/v/3mvHYMcnSec&hl=en_US&fs=1?rel=0"></param>
<param name="allowFullScreen" value="true"></param><param name=
"allowscriptaccess"value="always"></param><embed>src=
"http://www.youtube.com/v/3mvHYMcnSec&hl=en_US&fs=1?rel=0" type=
"application/x-shockwave-flash" allowscriptaccess="always"
allowfullscreen="true" width="640" height="385"></embed></object>

This is what you change it to:

<div class="YTvideos">
<object type="application/x-shockwave-flash"
data="http://www.youtube.com/v/3mvHYMcnSec&hl=en_US&fs=1?rel=0">
<param name="movie" value="http://www.youtube.com/v/3mvHYMcnSec&hl
=en_US&fs=1?rel=0" /> <param name="allowFullScreen" value="true" />
</object> </div>

I leave the script that follows the URL and the full screen parameter.

Add this to your css:

.YTvideos object{
	width:640px;
	height:385px;
}

Set the dimensions to what your embed requires. You can have videos of various sizes on your site by setting up different classes, one for each size. These few changes result in XHTML validity.

(0)

Possibly Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>