简体   繁体   English

获取嵌套在另一个iframe Chrome扩展程序中的iframe

[英]Getting an iframe that's nested within another iframe chrome extension

I've been trying to make an extension that gets the source of video players on the web by looking at the iframe sources, however it turns out a lot of those iframes have iframes nested inside of them where the actual video is, or sometimes it's even another iframe deep. 我一直在尝试通过查看iframe来源来扩展网络上的视频播放器的来源,但是事实证明,其中很多iframe都在其中嵌入了iframe,实际的视频在其中,或者有时甚至还有另一个iframe I've been trying to look deeper with things js like this: 我一直在尝试对js这样的东西进行更深入的研究:

var iframe = document.getElementsByTagName("iframe");
var nestedframes = iframe.getElementsByTagName("iframe");

and like this: 像这样:

var iframe = document.getElementsByTagName("iframe");
var innerDoc = iframe.contentWindow.webbody.innerHTML;
var nestedframes = innerDoc.getElementsByTagName("iframe");

but they return this error: contentscript.js:6 Uncaught TypeError: iframe.getElementsByTagName is not a function. 但他们返回此错误:contentscript.js:6未捕获的TypeError:iframe.getElementsByTagName不是一个函数。

If anyone has any ideas that would be greatly appreciated. 如果有人有任何想法,将不胜感激。

getElementsByTagName() method gets all elements on the document with the specified tag name. getElementsByTagName()方法获取具有指定标签名称的文档上的所有元素 It means that it gives you a list of elements. 这意味着它为您提供了元素列表

So you should itearate over it or select single element to call another DOM method. 因此,您应该对其进行迭代或选择单个元素来调用另一个DOM方法。 (Notice [0] ) (通知[0]

var iframe = document.getElementsByTagName("iframe")[0]; 
var nestedframes = iframe.getElementsByTagName("iframe");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM