Luc*_*ini 8 wordpress iframe jquery
我有一个Wordpress网站,其中的帖子被加载到iframe中.
这是有效的代码:
<a class="trick" rel="<?php the_permalink() ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a>
Run Code Online (Sandbox Code Playgroud)
$(文件).就绪(函数(){
Run Code Online (Sandbox Code Playgroud)$.ajaxSetup({cache:false}); $(".trick").click(function(){ var post_link = $(this).attr("rel"); $("#frame").css("display","block"); $("#frame").attr("url", post_link); $("body").css("overflow","hidden"); }); }); </script>
<iframe id="frame" frameborder="no" allowtransparency="true" width="100%" height="100%" scrolling="no" src=""></iframe>
Run Code Online (Sandbox Code Playgroud)
现在,如何从iframe内部关闭此加载的iframe?
主页是index.php(主要的wordpress循环),iframe的内容是single.php(单个帖子),没有页眉和页脚.
谢谢.
这就是我在single.php中得到的
<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>
Run Code Online (Sandbox Code Playgroud)
Sha*_*oli 17
执行以下代码,在single.php其中加载iframe.这将找到iframe使用父项window作为上下文并删除或隐藏它.
//You can call hide() if you want to just hide it
$('#iframe', window.parent.document).remove();
Run Code Online (Sandbox Code Playgroud)
我实际上知道一个小技巧.
在您的父页面上创建一个功能
var closeIFrame = function() {
$('#iframeid').remove();
}
Run Code Online (Sandbox Code Playgroud)
在iframe中,你想要从任何你想要的地方关闭电话
parent.closeIFrame();
Run Code Online (Sandbox Code Playgroud)
整蛊,不是吗?
| 归档时间: |
|
| 查看次数: |
30938 次 |
| 最近记录: |