且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从iframe访问和更改父页面(使用jquery)

更新时间:2023-12-01 19:27:04

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.