开发者

How to access the parent page elements of an Iframe

开发者 https://www.devze.com 2022-12-21 11:26 出处:网络
How to access the paren开发者_JAVA技巧t page elements of an Iframe. e.g. If i have a page index.htm and another page in an IFrame in index.htm and want to access the elements of index.htm from that I

How to access the paren开发者_JAVA技巧t page elements of an Iframe. e.g. If i have a page index.htm and another page in an IFrame in index.htm and want to access the elements of index.htm from that IFrame.


javascript:

parent.document.getElementById('myElement');

jquery:

$('#myElement', window.parent.document);


See my reply to a similar question here:
move input text from iframe to main window

basically, parent gives you the "window" object of the parent window. You can then access window.document to get document... and therefore, you can get window.document.getElementById() by using parent.document.getElementById(id);

0

精彩评论

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