Can I access to iframe 's parent's element from the iframe page

≯℡__Kan透↙ 提交于 2019-11-30 19:10:24

问题


First the two page in under the same domain

In the parent page.htm I have only a element like input#test,

then I set a iframe in the parent page,called child.htm,in the child.html I write js to find the parent input element,like

var parent = window.self.top;

but I can't use var input = $(parent).find('input#test') to find the input element in parent.htm

Can I access to it? How can I achieve that?


回答1:


Try

var input = $(window.self.top).contents().find('input#test');

or

var input = $(window.self.top.document).find('input#test');


来源:https://stackoverflow.com/questions/10792401/can-i-access-to-iframe-s-parents-element-from-the-iframe-page

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