YouTube iframe在Internet Explorer 8中嵌入抛出JavaScript错误

YouTube iframe embeds throw JavaScript errors in Internet Explorer 8

本文关键字:JavaScript 错误 iframe Internet Explorer YouTube      更新时间:2023-09-26

在Internet Explorer 8中查看时,似乎简单的YouTube iframe嵌入抛出JavaScript错误。希望有人能找到我做错了什么-除非这是一个新的bug?

如何复制:

  1. 打开ie8,按F12调出开发人员工具
  2. 切换到"Console"选项卡查看JavaScript控制台
  3. 访问http://ehough.com/ie8-youtube.html,这是一个直接从youtube.com复制的iframe嵌入,并查看JavaScript错误

错误:

SCRIPT5007: Unable to get value of the property 'getActivated': object is null or undefined 
ie8-youtube.html, line 28 character 128
SCRIPT5020: Expected ')' in regular expression 
html5player-vflR_cX32.js, line 675 character 708
SCRIPT438: Object doesn't support property or method 'SetReturnValue' 
www-embed-vflqDUnF8.js, line 66 character 56
SCRIPT438: Object doesn't support property or method 'SetReturnValue' 
uVlr4eYkNjY, line 1 character 1

有人对此有什么见解吗?

IE8及以下版本不支持很多现代的东西。但我很确定它可以在IE9及以上版本上运行。我测试了IE10(我的电脑上没有IE8了),它工作得很好。

在Youtube的嵌入功能上,曾经有一个单选按钮说"使用旧的嵌入代码"。这是老式的嵌入代码,使用Flash播放器而不是Iframe。

然而,Youtube在2014年年中取消了这个选项。

仍然有一种方法可以获得老式的嵌入代码。下面的代码片段显示了一个通用的旧式嵌入代码。

<object width="560" height="315"><param name="movie" 
value="http://www.youtube.com/v/ [your Youtube video URL here] ?version=3&hl=en_US"></param><param
name="allowFullScreen" value="true"></param><param 
name="allowscriptaccess" value="always"></param><embed 
src="http://www.youtube.com/v/ [your Youtube video URL here] ?version=3&hl=en_US" 
type="application/x-shockwave-flash" width="560" height="315" 
allowscriptaccess="always" 
allowfullscreen="true"></embed></object>

你看到文本"[你的Youtube视频URL在这里]"吗?将占位符替换为您在Youtube视频url末尾看到的随机内容。示例如下:

 https://youtube.com/watch?v=  NUjbKaUcxeA  之前

要嵌入上面的视频URL,您应该将"[您的Youtube视频URL在这里]"替换为"NUjbKaUcxeA"。"

如果你想让它在IE8,甚至IE7上工作,你应该使用老式的嵌入代码。老式的嵌入代码也适用于现代浏览器。