【发布时间】:2015-10-10 01:16:11
【问题描述】:
有一个 chrome 扩展程序允许为 youtube iframe 中包含的 html5 视频设置和更改播放率。
我想在 Firefox(或者更好的是,独立于浏览器)上完成同样的事情。
我想知道我是否必须通过附加组件来执行此操作(因为我的 html 不在 YouTube 上,但我的视频在,所以能够跨站点进行消息传递),或者是否有更简单的方法(甚至可以跨浏览器工作)。
关于此事的任何想法都会很有用。
根据 Rachel Gallen(在 cmets 中)的出色建议,我尝试了以下一些方法:
$(function (){
// a convenient way to get at things once the page renders
$("button#stop-me").click(function() {
var mytags = document.getElementsByTagName("video");
});
});
$(function (){
// a convenient way to get at things once the page renders
$("button#stop-me").click(function() {
var myframe = document.getElementsByTagName("iframe");
for(p in myframe)
{
var mytags = myframe.document.getElementsByTagName("video");
}
});
});
$(function (){
document.addEventListener('DOMNodeInserted', function(event) {
var node = event.target || null;
if (node && node.nodeName === 'VIDEO') {
nodeList.push(node);
}
});
$("button#stop-me").click(function() {
alert(nodeList.length);
});
});
第一个返回一个空的“mytags”。
第二个返回 iframe 列表,但 myframe.document 调用出错(如预期的那样)。
第三个 on 永远不会碰到 nodeList.push(node) 行并显示计数为 0(如预期)
【问题讨论】:
标签: html video cross-domain