关闭iframe时如何刷新父页面-jQuery [英] How to refresh a parent page when closing an iframe - jquery

查看:431
本文介绍了关闭iframe时如何刷新父页面-jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户关闭iframe时,我需要刷新我的网页

i need to refresh my webpage when the user close an iframe

var iframe = $('#layer-frame').contents();

iframe.find(".close").click(function(){
  alert("test");
});

我有上面的代码,似乎没有捕获我的点击事件.如何添加页面刷新功能..请帮助

I have the above code which doesnt seem to capture my click event. How to add the functionality of page refresh..please help

推荐答案

这里有一些技巧-您可以尝试捕获框架冒泡的点击事件-

Here is some trick - you can try to catch frame bubbling click event -

父页面

<html>
    <head>
        <title>testpage</title>
        <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
        <script>
            $(function(){
                var frame = window.frames[0] // first in may case

                $(frame).on("click", function(e){

                    if($(e.target).is('.close')){
                        window.location.reload();
                    }

                });
            })
        </script>
    </head>
    <body>
       <div><iframe src="iframe.html"/></div>
    </body>
</html>

iframe

<div class="root">
    <span class="close">click</span>
</div>

这篇关于关闭iframe时如何刷新父页面-jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆