简体   繁体   中英

Access DOM from 'dynamic' iframe

I'm working on a simple Chrome extensions that alters an existing webpage. Unfortunately the webpage uses some iframes which makes it a bit more difficult to access the DOM.

I want to access the elements from mainFrame but its content seems to be generated dynamically (not really sure how this works). The src refers to blank.htm which is empty.

document.getElementById("mainFrame").contentDocument

This gets the content of the empty blank.htm

<frame src="blank.htm" name="mainFrame" id="mainFrame" title="mainFrame" />

And with this:

document.getElementById("mainFrame")

I can see the DOM, but I don't know how to further select elements. I might be able to access them with ...('mainFrame").childNodes[i] , but I rather select them with their classes or ids.

Iframe dom contents are not accessible from the parent document. Only thing you can do is the reverse one, yaah you can access the parent document's DOM from iframe. Those are all restricted due to security reasons. But you can access them from chrome extension functions(if you are working for chrome extensions).

For more details about accessing iframe content in chrome extension please follow the link

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