Access child iFrame DOM from parent page

不想你离开。 提交于 2019-11-27 07:52:39

There is a way. When the page in the iframe loads, have it do the following

parent.childGetElementById = function (id) {return document.getElementById(id);}
parent.childLoaded();

This will make a function in the global scope of the parent page (that contains the iframe). Then in the parent, just have the following

function childLoaded() {var dom = childGetElementById('someid');}

This is along as you have control of the page your loading into the iframe... if you do not, you are out of luck.

This is a browser security measure, otherwise everybody would be wrapping your banking websites and skimming off your passwords when you logged in.

You can talk from the iframe to the parent, but not back into an iframe again.

You're out of luck, as far as I know. You can talk between them using the hash-bang in the URL though, see this for a decent discussion.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!