简体   繁体   中英

Changing the contents of an iframe

I have an iframe embedded on my webpage and I'd like to edit certain parts of it using javascript. Is this possible and how would I do it?

Since the iframe is loading content from another domain — no. You'll hit the same origin policy.

According to the HTML DOM spec (level 2) , you can reach the child DOM by using the .contentDocument property of the iframe's DOM node.

But, of course, no browser lets you do that across domains anymore...

You can get the iframe document by doing this:

document.getElementById(iframeId).contentDocument

That is if you own the page loaded in the 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