我有一个最初不包含视频的 iframe
。当用户按下按钮时,将加载 Youtube 视频。为了检测 Youtube 视频何时完成加载,我使用 on()
来检测 Youtube iframe 的 DOM 结构何时被修改。目前,当视频加载时,我在控制台中没有看到 Video Loaded
消息。我的逻辑有问题吗?
<div id="button">BUTTON</div>
<div id="container">
<iframe id="ytplayer" class="hide" type="text/html" width="840" height="470"
src="https://www.youtube.com/embed/" frameborder="0" allowfullscreen></iframe>
</div>
$(document).ready(function() {
$('#button').click( function() {
$('#ytplayer').attr('src', 'https://www.youtube.com/embed/w7bccxRvxDc?rel=0&showinfo=0');
});
$('#container').on('DOMNodeInserted', '#ytplayer', function() {
console.log('Video Loaded');
});
});
最佳答案
您可能想看看 YouTube iframe API 。它支持许多事件,包括加载视频时。该 API 受到官方支持,因此如果 Google 将来进行更改,您无需支持自定义构建的代码。
关于jquery - 检查 Youtube iFrame 内的内容是否已更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15261534/