javascript 任何人都可以从子 iframe 关闭由 Jquery 插件 bPopup 生成的弹出窗口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4247710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 10:46:24  来源:igfitidea点击:

Anyone can close the popup generated by Jquery plugin bPopup, from a child iframe?

javascriptjquerymodalpopupsbpopup

提问by fred

Okay, the story is abit long but hope you can bear with me so that there could be some background to the problem:

好的,这个故事有点长,但希望你能忍受我,以便有一些问题的背景:

I'm developing the registration section for a portal using ASP.NET and to make things nice, I decided to use bPopup from hereto load the registration page into the iframe of the calling page (parent page). Now I need a way to close down the iframe after a successful registration so from the codebehind of the registration page (nested in the iframe) I tried a Javascript function from the parent that allows me to do so, here's the function to close the iframe generated by the plugin:

我正在使用 ASP.NET 为门户开发注册部分,为了让事情变得更好,我决定使用 bPopup 从这里将注册页面加载到调用页面(父页面)的 iframe 中。现在我需要一种在成功注册后关闭 iframe 的方法,所以从注册页面的代码隐藏(嵌套在 iframe 中)我尝试了父级的 Javascript 函数,它允许我这样做,这是关闭 iframe 的函数由插件生成:

 function bPopup_close() {
         $(".bClose").closePopup();
     return false;
 }

and here's the code behind from the iframe (the function will be called on submit):

这是 iframe 背后的代码(该函数将在提交时调用):

    ClientScript.RegisterOnSubmitStatement
        (GetType(), "Javascript", "javascript: window.opener.bPopup_close();");

I wasn't able to close the popup. Interestingly, Firebug showed me that after I clicked the submit button, window.opener was null. Does that mean that the parent was indeed closed? Anyway the popup was still there...

我无法关闭弹出窗口。有趣的是,Firebug 显示我在单击提交按钮后,window.opener 为空。这是否意味着父级确实已关闭?无论如何,弹出窗口仍然存在......

Hope you guys could share some insights on anything similar?

希望大家能分享一些类似的见解?

回答by Bruno

I can see that dinbror already answered you on his page :)

我可以看到 dinbror 已经在他的页面上回答了你 :)

@fred: Glad you like it. Are you using the newest version of bPopup?

Solution: Create a function on the page which opens the popup:

function closeBPopup() { $(selector).bPopup().close() }

Then you can trigger it inside your iframe whenever you are done doing your stuff with:

parent.closeBPopup();

@fred:很高兴你喜欢它。您使用的是最新版本的 bPopup 吗?

解决方案:在打开弹出窗口的页面上创建一个函数:

函数 closeBPopup() { $(selector).bPopup().close() }

然后,您可以在完成以下操作时在 iframe 中触发它:

parent.closeBPopup();

回答by fred

After half a day, I finally got it working with:

半天后,我终于得到了它的工作:

ClientScript.RegisterStartupScript (GetType(), "blah", "< script type=\"text/javascript\">bclose(); < /script> ", false);

ClientScript.RegisterStartupScript (GetType(), "blah", "< script type=\"text/javascript\">bclose(); < /script> ", false);

and the code bclose() is:

代码 bclose() 是:

    function bclose() {
        parent.$("#popup").bPopup().close();
        return false;
    }
    function bclose() {
        parent.$("#popup").bPopup().close();
        return false;
    }