在没有 SWFObject 的 IE6 中使用 jQuery 嵌入 YouTube 视频

发布于 2024-08-22 16:32:14 字数 1981 浏览 7 评论 0原文

这是我的代码:

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<title></title>
<script>
$(document).ready(function(){
$("#video").html('<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/HPPj6viIBmU&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/HPPj6viIBmU&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>');
});
</script>
</head>
<body>
  <div id="video"></div>
</body>
</html>

它适用于 Firefox 和 Chrome,但在 IE6 中有些不太正确。遗憾的是,项目要求之一是支持该浏览器,因此即使它可以在 IE7 中运行,我也需要解决这个问题。

我知道有 SWFObject,但我不想使用它(我们已经加载了一堆 JS 文件,我们不需要更多)。

即使这样也行不通:

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

IE6 似乎忽略了 标记,这是它嵌入的代码。

<EMBED src=http://www.youtube.com/v/HPPj6viIBmU&amp;hl=en_US&amp;fs=1&amp; width=480 height=385 type=application/x-shockwave-flash allowfullscreen="true" allowscriptaccess="always"></EMBED>

有解决方法吗?

谢谢。

Here's my code:

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<title></title>
<script>
$(document).ready(function(){
$("#video").html('<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/HPPj6viIBmU&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/HPPj6viIBmU&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>');
});
</script>
</head>
<body>
  <div id="video"></div>
</body>
</html>

It works with Firefox and Chrome, but something's not quite right in IE6. Sadly, one of the project requirements is supporting this browser, so even if it workis in IE7, I need to work this out.

I know there's SWFObject, but I'd rather not use it (we are loading already a bunch of JS files, we don't want more).

Even this won't work:

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

It seems that IE6 ignores the <object> tag, here's the code it embeds.

<EMBED src=http://www.youtube.com/v/HPPj6viIBmU&hl=en_US&fs=1& width=480 height=385 type=application/x-shockwave-flash allowfullscreen="true" allowscriptaccess="always"></EMBED>

Is there a workaround?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南汐寒笙箫 2024-08-29 16:32:14

您寻找的解决方法将以编写 swfobject 的等效项结束,除非它不会经过很好的测试或执行。既然已经有一个完美的现有解决方案,特别是当它缩小到只有 10KB 时,为什么还要重新发明轮子呢?如果您决定不添加另一个 http 请求,为什么不将 swfobject 代码滑入页面或另一个 js 文件中。

我从不使用 swfobject 以外的任何东西来嵌入 flash。

The workaround you look for is going to end with you writing the equivilant of swfobject, except it won't be as well tested or perform as well. Why reinvent the wheel when there is a perfectly good existing solution, especially when it is only 10KB minified? if you are deadset on not adding another http request, why not slipstream the swfobject code into the page or into another js file.

I never use anything other than swfobject for embedding flash.

梦中楼上月下 2024-08-29 16:32:14

这有点奇怪,因为最初对象标签是由 MS 引入的,用于嵌入 flash-objects。

尝试将 classid 参数添加到您的对象标签中,例如:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="300" height="120">
    <param name="movie" value="myContent.swf" />    
</object>

This is a bit weird, because originally the object tag was inctroduced by MS to embed flash-objects.

Try to add the classid-parameter to your object-tag, eg:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="300" height="120">
    <param name="movie" value="myContent.swf" />    
</object>
月牙弯弯 2024-08-29 16:32:14

除了使用 SWFObject 之外,您还必须手动检测 IE,然后使用

<embed>

类似以下内容:

var isMSIE = /*@cc_on!@*/false;
if(isMSIE)
{
 //use embed tag
}
else
{
 //use object
}

请参阅: http ://kb2.adobe.com/cps/127/tn_12701.html
用于嵌入和对象属性。

我认为您的嵌入标记的问题在于您无法将 Flash 变量放入其中。他们必须进入 flashvars。上面的链接将阐明如何执行此操作。但最好的测试方法是赋予它最小的属性,然后添加更多属性来查看是什么破坏了它。

IE6 的简单嵌入标签如下所示:

<embed src="MyFlashMovie.swf" quality="high" width="320" height="240" name ="MyMovieName" type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>

Beside using SWFObject you will have to manually detect IE and then use

<embed>

Something like this:

var isMSIE = /*@cc_on!@*/false;
if(isMSIE)
{
 //use embed tag
}
else
{
 //use object
}

See: http://kb2.adobe.com/cps/127/tn_12701.html
for embed and object properties.

I think the problem with your embed tag is that you cannot place Flash variables inside of it. They must go into flashvars. The link above will clarify how to do this. But the best way to test is to give it the minnimum properties and then add more to see what is breaking it.

A simple embed tag for IE6 looks like this:

<embed src="MyFlashMovie.swf" quality="high" width="320" height="240" name ="MyMovieName" type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>
゛清羽墨安 2024-08-29 16:32:14

对于嵌入或对象标签,有时需要使用 DOM createElement 和 insertBefore 或appendChild 方法,而不是简单地使用 document.write 写出 html。当您使用 DOM 方法时,它会通知浏览器正在动态添加新元素,并且浏览器应该对其进行处理以将其转换为插件对象。请参阅这个书签我调整了 Silverlight 对象的大小并将其插入到现有的 HTML 文档中。

For embed or object tags you sometimes need to use the DOM createElement and insertBefore or appendChild methods instead of simply writing out the html using document.write. When you use the DOM methods it will notify the browser that a new element is being added dynamically and the browser should process it to turn it into a plugin object. See this bookmarklet that I made to resize a Silverlight object and insert it into an existing HTML document.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文