从iframe访问和更改父页面(使用jquery) [英] access and change parent page from iframe (with jquery)
问题描述
< body>如何从iframe访问parrent页面(并更改parrent页面)?
< iframe src =frame1.htmlname =frame1height =100%>< / iframe>
< div id =test1>< / div>
< / body>
在frame1.html中是< a href = ..>
,并且我想将文字< h1>点击< / h1>
添加到< div id =test1 >< / div>
,当< a href ..>
被点击时。
谢谢。 如果您的子页面(frame1.html)位于与您可以在子窗口中编写如下所示的代码:
$('#test1',parent.document )。html的( '< H1>点击< / H1>');
第二个参数提供上下文
,其中搜索第一个参数匹配的元素。该文档位于以下位置: http://api.jquery.com/jQuery/#jQuery -selector-context
jQuery(selector [,context])
所以,你的代码(frame1.html)可以像这样:
< a href =...
onclick =$('#test1',parent.document).html('< h1> clicked< / h1>') ;>点击我< / a>
希望这有助于您。
is there any way how to access from iframe to parrent page (and change parrent page)?
<body>
<iframe src="frame1.html" name="frame1" height="100%"></iframe>
<div id="test1"></div>
</body>
In frame1.html is <a href=..>
and I want to add text "<h1>clicked</h1>
" into <div id="test1"></div>
, when the <a href..>
was clicked.
Thanks.
If your child page (frame1.html) is located at the same domain as the parent page, You can write a code like below in the child window :
$('#test1', parent.document).html('<h1>clicked</h1>');
The second parameter provides the context
in which to search the element matched by the first parameter. The Document is here:http://api.jquery.com/jQuery/#jQuery-selector-context
jQuery( selector [, context ] )
So, your code (frame1.html) could go like this:
<a href="..."
onclick="$('#test1', parent.document).html('<h1>clicked</h1>');">click me</a>
Hope this helps.
这篇关于从iframe访问和更改父页面(使用jquery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!