关闭 fancybox 窗口:适用于 iframe 但不适用于 ajax

发布于 2025-01-05 04:21:39 字数 1039 浏览 2 评论 0原文

我有一个工作 fancybox 模态窗口,其中包含下一个代码:

        $("a#add-project").click(function(){
            $.fancybox({
                type: 'ajax',
                href: BASEPATH + 'time/addProject',
                fitToView: false,
                autoSize: false,
                width: 500,
                height: 300,
                closeClick: false,
                openEffect: 'none',
                closeEffect: 'none',
                beforeClose: function() {
                    console.log('closed');
                }
            });
        });

AJAX 窗口包含一个带有下一个代码的按钮:

    $('#addproject-close').bind("click keypress", function(){
        $.fancybox.close(true); 
        $.fancybox.close();
        parent.$.fancybox.close(true);
        parent.$.fancybox.close();
        console.log('tried to close');
    });

我知道它可以工作,因为我在控制台上看到 尝试关闭 消息,但没有办法关闭该窗口。我尝试了所有可能的事情,但一无所获。过去,我有一个类型为“iframe”且带有parent.$...的窗口。

我怎样才能在ajax中做到这一点?

先感谢您

I have a working fancybox modal window with the next code:

        $("a#add-project").click(function(){
            $.fancybox({
                type: 'ajax',
                href: BASEPATH + 'time/addProject',
                fitToView: false,
                autoSize: false,
                width: 500,
                height: 300,
                closeClick: false,
                openEffect: 'none',
                closeEffect: 'none',
                beforeClose: function() {
                    console.log('closed');
                }
            });
        });

That AJAX window contains a button with the next code:

    $('#addproject-close').bind("click keypress", function(){
        $.fancybox.close(true); 
        $.fancybox.close();
        parent.$.fancybox.close(true);
        parent.$.fancybox.close();
        console.log('tried to close');
    });

I know that it works because I see the tried to close message on console but there is NO way to close that window. I tried with all the possible things but nothing. In the past I had this window with type: 'iframe' and with parent.$... just worked.

How I can do it in ajax?

Thank you in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱冒险 2025-01-12 04:21:39

在 AJAX 窗口中,像这样创建关闭按钮:

<a href="javascript:$.fancybox.close();" id="addproject-close">close fancybox</a>

... 并忘记 .bind() 方法。

那应该可以解决问题。 查看演示

Inside your AJAX window, create your closing button like this:

<a href="javascript:$.fancybox.close();" id="addproject-close">close fancybox</a>

... and forget about the .bind() method.

That should do the trick. See demo

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文