Robert
Robert

Reputation: 21388

Embedded YouTube code does not validate

While validating my not be a big issue to some people, I personally want my page to validate whenever possible, as I feel it's a good habit to code properly whether the compiler/browser/person reading your code understands anyways.

Anyways, I'm building a website for a client that is requesting a YouTube video of theirs be embedded in the page. Easy, I grab the code from YouTube and throw it in the page. It works of course, but the page now doesn't validate under XHTML 1.0 Strict solely because of the YouTube-generated code.

The part that doesn't validate is the embed portion, and it works fine without this line in Chrome, but breaks in Firefox/IE. If it was just IE I'd just shrug it off as IE being terrible as per usual, but being as Firefox is doing it as well I'm wondering how to approach the situation. I could just dynamically input the content based on the browser, therefore validating, but that seems sloppy.

Am I fighting a losing battle and should just ignore the fact that this page doesn't validate because of this snippet?

Not actual video, just example code

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

Upvotes: 2

Views: 2918

Answers (4)

user5340092
user5340092

Reputation:

I'm afraid the above answers still cause validation to fail on W3C. Here's a solution which works for xhtml strict;

<object type="application/x-shockwave-flash" data="https://www.youtube.com/v/YourVideoID" width="100%" height="100%"></object>

Upvotes: 0

Daniel Cassidy
Daniel Cassidy

Reputation: 25617

<object type="application/x-shockwave-flash"
    data="http://www.youtube.com/v/oHg5SJYRHA0?fs=1&amp;hl=en_US"
    width="480" height="385">
  <param name="movie"
      value="http://www.youtube.com/v/oHg5SJYRHA0?fs=1&amp;hl=en_US"/>
  <param name="allowFullScreen" value="true"/>
  <param name="allowscriptaccess" value="always"/>
</object>

That should work on IE, Firefox, Opera, Safari and Chrome.

The data attribute of <object> and the movie parameter must both be present and must have the same value.

In IE this prevents the SWF from streaming and, for example, presenting a pre-loader, but that should be a non-issue for YouTube.

For more, and for a fix for that last problem, see Flash Satay: Embedding Flash While Supporting Standards.

Upvotes: 3

Moses
Moses

Reputation: 9173

The <embed> tag is new to HTML5 and it's quite possible that the validator you are using is not fully up-to-date. All of that code should be quite fine in XHTML 1.0 strict.

Upvotes: 0

fehays
fehays

Reputation: 3167

I think if you use swfobject you could get it to validate.

http://code.google.com/p/swfobject/

Upvotes: 0

Related Questions