开发者

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/oHg5SJYR开发者_运维问答HA0?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed>
</object>


<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.


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

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


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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜