jquery – 如何从iframe内关闭iframe?

前端之家收集整理的这篇文章主要介绍了jquery – 如何从iframe内关闭iframe?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个wordpress网站,帖子被加载到iframe中.

这是有效的代码

@H_502_4@<a class="trick" rel="<?PHP the_permalink() ?>" href="<?PHP the_permalink() ?>"><?PHP the_title(); ?></a>

$(document).ready(function(){

06001

@H_502_4@<iframe id="frame" frameborder="no" allowtransparency="true" width="100%" height="100%" scrolling="no" src=""></iframe>

现在,如何从iframe内部关闭此加载的iframe?

页面是index.PHP(主要的wordpress循环),iframe的内容是single.PHP(单个帖子),没有页眉和页脚.

谢谢.

这就是我在single.PHP中得到的

@H_502_4@<head> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function(){ $("#close").click(function(){ $('#frame',window.parent.document).remove(); }); }); </script> </head> <body> <div id="container-single"> <button id="close" >Close</button> <?PHP if (have_posts()) : while (have_posts()) : the_post(); ?> <article <?PHP post_class('single') ?> id="post-<?PHP the_ID(); ?>"> <h1 class="entry-title"><?PHP the_title(); ?></h1> <div class="entry-content"> <?PHP the_content(); ?> <?PHP wp_link_pages(array('before' => 'Pages: ','next_or_number' => 'number')); ?> <?PHP the_tags( 'Tags: ',',''); ?> <?PHP include (TEMPLATEPATH . '/_/inc/Meta.PHP' ); ?> </div> </article> <?PHP endwhile; endif; ?> </div> </body>

解决方法

从iframe中加载的single.PHP执行以下代码.这将使用父窗口作为上下文找到iframe并删除或隐藏它. @H_502_4@//You can call hide() if you want to just hide it $('#iframe',window.parent.document).remove();

猜你在找的jQuery相关文章