简体   繁体   English

在Fancybox3中使用afterClose事件

[英]Using afterClose event with Fancybox3

How can I create an afterclose event with FancyBox3? 如何使用FancyBox3创建Afterclose事件? I'm using afterClose event with the second version of fancybox but i'm trying to upgrade to fancybox3 and the instructions say to put the options in "data-options" attribute. 我正在将afterClose事件与fancybox的第二个版本一起使用,但是我正尝试升级到fancybox3,并且说明要求将选项置于“ data-options”属性中。

Here's what i tried: 这是我尝试过的:

  <a data-fancybox data-type="iframe" data-src="http://www.example.com" href="javascript:;"
     data-options='{

                afterClose  : function() {
                    location.href = "http://www.google.com";
                }
                   }'>

and also: 并且:

<script>
        $("[data-fancybox]").fancybox({
    afterClose  : function() {
                    location.href = "http://www.google.com";
                }

        });
</script>

The code into the HTML attributes won't work as you expected, because it's just a simple text but not a real js function, so to make it work you shoul put the code into the js file, and you are missing something, so please try this HTML属性中的代码无法按预期工作,因为它只是一个简单的文本,而不是真正的js函数,因此,要使其正常工作,您应该将代码放入js文件中,而您丢失了某些内容,因此请尝试这个

$.fancybox.open({
    src  : '#hidden-content',
    type : 'inline',
    opts : {
        afterShow : function( instance, current ) {
            console.info( 'done!' );
        }
    }
});

As the documentation says: https://fancyapps.com/fancybox/3/docs/#api 如文档所述: https : //fancyapps.com/fancybox/3/docs/#api

Your 2nd snippet should work, see this demo - https://codepen.io/anon/pen/OQmBZy?editors=1010 您的第二个片段应该可以正常工作,请参见此演示-https: //codepen.io/anon/pen/OQmBZy?editors=1010

HTML 的HTML

  <a data-fancybox="test" data-type="iframe" data-src="https://codepen.io/about/" href="javascript:;">
    External page
  </a>

JS JS

$('[data-fancybox="test"]').fancybox({
  afterClose  : function() {
    alert('Done!');
    location.href = "https://www.google.com";
  }
});

I have put alert('Done!') to see that callback executes. 我已经放了alert('Done!')来执行回调。 Google will prevent to load itself into an iframe, therefore you will see just blank page. Google会阻止将自身加载到iframe中,因此您只会看到空白页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM