开发者

Changing the contents of an iframe

开发者 https://www.devze.com 2022-12-25 03:59 出处:网络
I have an iframe embedded on my webpage and I\'d like to e开发者_JS百科dit certain parts of it using javascript. Is this possible and how would I do it?Since the iframe is loading content from another

I have an iframe embedded on my webpage and I'd like to e开发者_JS百科dit 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消