【发布时间】:2016-04-28 08:21:12
【问题描述】:
我的 youtube javascript player api 有问题。
我称之为js代码:
function onYouTubeIframeAPIReady() {
var podcast = document.getElementById('podcast')
var player = new YT.Player( document.getElementById('podcast'));
player.addEventListener('onStateChange', function(e) {
if (e.data === 1) {
alert("play");
}
});
};
使用此 html 代码:
<iframe id="podcast" type="text/html" width="720" height="405"
src="https://www.youtube.com/embed/XXXXXX?cc_load_policy=1&enablejsapi=1&theme=light"
frameborder="0" allowfullscreen>
问题是我使用的是pjax系统,所以导航时全局javascript代码没有重新加载。 因此,当 pjax:success 时,我重新加载了部分 javascript 代码。我尝试过这样的事情:
$(document).on('pjax:success', function() {
onYouTubeIframeAPIReady();
}
但它不起作用。我的问题是如何重新加载 onYouTubeIframeAPIReady();当它必须像那里所说的那样被全局定义时onYouTubeIframeAPIReady function is not calling
【问题讨论】:
标签: youtube-javascript-api pjax