如何关闭全屏iframe?

时间:2012-03-01 21:51:43

标签: jquery wordpress iframe

我有一个wordpress网站,它在一个iframe中加载帖子的内容,其中位置固定,宽度和高度为100%。这是悬停在所有网站......

我有一个关闭按钮;如何告诉按钮隐藏iframe并在其下显示内容?

P.S。抱歉我的英文。

由于

<h2><a class="trick" rel="<?php the_permalink() ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>

$(document).ready(function(){
  $.ajaxSetup({cache:false});
  $(".trick").click(function(){
    var post_link = $(this).attr("rel");
    $("#frame").attr("url", post_link);
    return false;
  });
});

1 个答案:

答案 0 :(得分:0)

如果您想从iframe中的按钮关闭iframe,则需要以下内容:

<button onclick="parent.window.location.hash ='close'">close</button>

这将更改您网址中的参考号。例如:yourwebiste.com/yourpage.php#close
然后,您需要检查何时使用类似的内容(在父文件中)调用此引用:

    var close_iframe = false;

setInterval(function(){

    if(!close_iframe){

        hash_val = window.location.hash;

        if (hash_arr[0] == "#close"){

            $(#iframe_id).hide();
            close_iframe = true;

        }
    }

  }, 100);

希望我足够清楚它对你有帮助,对不起,这是我的第一个回答呵呵。