jQuery 提交登录表单后关闭 Fancybox 模式窗口并重新加载页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13410582/
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-08-26 12:35:40  来源:igfitidea点击:

Close Fancybox modal window and reload the page after login form has been submitted

jqueryfancyboxfancybox-2

提问by Stephen

I've got a login form opening in a FancyBox 2 modal iframe window. But when you submit the form, the web page is opening within the modal.

我在 FancyBox 2 模态 iframe 窗口中打开了一个登录表单。但是当您提交表单时,网页会在模态中打开。

Can anyone tell me if and how to make the Fancybox modal close, and the underlying page re-load when the login form is submitted please?

谁能告诉我是否以及如何关闭 Fancybox 模式,并在提交登录表单时重新加载底层页面?

Here's my current code - within a functions.js file:

这是我当前的代码 - 在 functions.js 文件中:

  $(".login-popup").fancybox({
    maxWidth    : 310,
    height      : 300,
    autoSize    : false,
    closeClick  : false,
    openEffect  : 'none',
    closeEffect : 'none'
  });

And here's my login link:

这是我的登录链接:

<a class="login-popup" data-fancybox-type="iframe" href="/popup/login" title="">Login</a>

Thanks for any help,

谢谢你的帮助,

Ste

Edit 1:

编辑1:

Thanks for the help with this. Sorry for being a complete newbie, but I'm having trouble getting the parent.$.fancybox.close(); to work on the form submit() event. Here's the code I'm now using but it doens't close the window as I'm doing something wrong. Any ideas what? Thanks.

感谢您的帮助。对不起,我是一个完整的新手,但我在获取 parent.$.fancybox.close(); 时遇到了麻烦。处理表单 submit() 事件。这是我现在使用的代码,但它不会关闭窗口,因为我做错了什么。有什么想法吗?谢谢。

$(".login-popup").fancybox({
    closeEffect : 'none',
    'afterClose':function () {
      window.location.reload();
    },
  });

$(".login-form").submit(function(){
  parent.fancyBoxClose();
});

回答by kayen

To close the fancybox from within the iframe, you can use parent.$.fancybox.close();on the formsubmit()event.

要从 iframe 中关闭fancybox,您可以parent.$.fancybox.close();formsubmit()事件上使用。

Then add an onClose event on the Fancybox initializer, which would reload the page:

然后在 Fancybox 初始化程序上添加一个 onClose 事件,这将重新加载页面:

$(".login-popup").fancybox({
    maxWidth    : 310,
    height      : 300,
    autoSize    : false,
    closeClick  : false,
    openEffect  : 'none',
    closeEffect : 'none',
    'afterClose':function () {
        window.location.reload();
    },
  });