简体   繁体   中英

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. I've been trying to look deeper with things js like this:

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.

If anyone has any ideas that would be greatly appreciated.

getElementsByTagName() method gets all elements on the document with the specified tag name. 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. (Notice [0] )

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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