javascript Fancybox afterClose 事件不起作用

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

Fancybox afterClose event not working

javascriptjqueryfancyboxfancybox-2

提问by Thempower

I'm having a problem using the fancybox API after Close.

关闭后我在使用fancybox API 时遇到问题。

I open the function when people click on this:

当人们点击这个时,我打开这个功能:

<a class="fancybox fancybox.iframe btn" href="myurl.php"></a>

The javascript behind this is:

这背后的javascript是:

$('.fancybox.iframe')
    .fancybox({
    arrows: false,
    padding: 0,
    overlay: {
        locked: false
    },
    beforeClose: function () {
        location.reload();
    }
});

And it never reload the page when I close it. Can somebody help me? Thank you !

当我关闭它时,它永远不会重新加载页面。有人可以帮助我吗?谢谢 !

回答by JFK

Some clarification to avoid further confusion:

一些澄清以避免进一步混淆:

Based on your html

基于你的 html

<a class="fancybox fancybox.iframe btn" href="myurl.php"></a>
  1. Use the afterClosecallback (not an event) instead of beforeClose. For further reference check Tips & Tricks=> No.11

  2. The classfancyboxis used to bind the selector to fancybox so your initialization code should look like this

    jQuery(document).ready(function ($) {
        $('.fancybox').fancybox({
            arrows: false,
            padding: 0,
            helpers: {
                overlay: {
                    locked: false
                }
            },
            afterClose: function () {
                location.reload();
            }
        });
    }); // ready
    
  3. The (valid) fancybox.iframeclasstells fancybox the type of content it should handle, but you don't use it to bind the selector to fancybox.

  1. 使用afterClose回调(不是event)而不是beforeClose. 如需进一步参考,请查看提示和技巧=> No.11

  2. fancybox是用来选择绑定的fancybox所以你的初始化代码应该是这样的

    jQuery(document).ready(function ($) {
        $('.fancybox').fancybox({
            arrows: false,
            padding: 0,
            helpers: {
                overlay: {
                    locked: false
                }
            },
            afterClose: function () {
                location.reload();
            }
        });
    }); // ready
    
  3. (valid)fancybox.iframe告诉fancybox 它应该处理的内容类型,但您不使用它来将选择器绑定到fancybox。

See JSFIDDLE

JSFIDDLE

NOTE: this is for fancybox v2.x

注意:这是用于fancybox v2.x

回答by Kenneth

You should use

你应该使用

$('.fancybox.iframe').fancybox({
    arrows: false,
    padding: 0,
    helpers: { overlay : {closeClick: false} },
    beforeClose: function () {
        parent.location.reload(true);
    }
});

(Note that the syntax is different between version 1 and 2 of fancybox. The above is for fancybox2)

(注意,fancybox 1 和 2 版本的语法是不同的,以上是针对fancybox2的)

回答by Manjar

Try using onCloseevent:

尝试使用onClose事件:

$('.fancybox.iframe')
.fancybox({
    arrows : false,
    padding: 0,
    overlay: {
        locked: false
    },
    onClosed: function() {
        location.reload(); 
    }

});

According to the API there is no beforeCloseevent, but there is onClose

根据 API 没有beforeClose事件,但是有onClose

http://fancybox.net/api

http://fancybox.net/api