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

£可爱£侵袭症+ 提交于 2020-01-03 20:16:30

问题


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.

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?

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

  $(".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:

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.

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

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

回答1:


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

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

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


来源:https://stackoverflow.com/questions/13410582/close-fancybox-modal-window-and-reload-the-page-after-login-form-has-been-submit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!