【发布时间】:2014-12-14 21:25:18
【问题描述】:
我正在编写一个嵌入 YouTube 视频的 Google Chrome 扩展程序:
<iframe id="ytplayer" type="text/html" width="640" height="360"
src="https://www.youtube.com/embed/M7lc1UVf-VE"
frameborder="0" allowfullscreen>
然后我在下方添加了一个按钮,用户可以单击该按钮以全屏播放此视频:
<a href="#" id="lnkFullScreen">Play full screen</a>
这项工作是通过 JavaScript(和 jQuery)使用代码 I found here 完成的:
$("#lnkFullScreen").click(function(e)
{
e.stopPropagation();
e.preventDefault();
var playerElement = document.getElementById("ytplayer");
playerElement.playVideo(); //`playVideo` is undefined
var requestFullScreen = playerElement.requestFullScreen || playerElement.mozRequestFullScreen || playerElement.webkitRequestFullScreen;
if (requestFullScreen)
{
requestFullScreen.bind(playerElement)();
}
});
但是当我运行此代码时,playVideo 函数是 undefined 对应于 playerElement。
知道我做错了什么吗?
PS。我希望我的播放器保留在 HTML5 中。
【问题讨论】:
-
没有足够的代表发表评论。这可能会有所帮助stackoverflow.com/questions/7615380/…
-
@codemonkeytony:我在我的问题中引用了相同的链接。你有什么特别想指出的吗?
-
好吧,如果没有别的,你可以只修改宽度和高度。
标签: javascript google-chrome google-chrome-extension youtube youtube-api