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
Fancybox afterClose event not working
提问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>
Use the
afterClose
callback (not anevent
) instead ofbeforeClose
. For further reference check Tips & Tricks=> No.11The class
fancybox
is used to bind the selector to fancybox so your initialization code should look like thisjQuery(document).ready(function ($) { $('.fancybox').fancybox({ arrows: false, padding: 0, helpers: { overlay: { locked: false } }, afterClose: function () { location.reload(); } }); }); // ready
The (valid)
fancybox.iframe
classtells fancybox the type of content it should handle, but you don't use it to bind the selector to fancybox.
使用
afterClose
回调(不是event
)而不是beforeClose
. 如需进一步参考,请查看提示和技巧=> No.11该班
fancybox
是用来选择绑定的fancybox所以你的初始化代码应该是这样的jQuery(document).ready(function ($) { $('.fancybox').fancybox({ arrows: false, padding: 0, helpers: { overlay: { locked: false } }, afterClose: function () { location.reload(); } }); }); // ready
(valid)
fancybox.iframe
类告诉fancybox 它应该处理的内容类型,但您不使用它来将选择器绑定到fancybox。
See 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 onClose
event:
尝试使用onClose
事件:
$('.fancybox.iframe')
.fancybox({
arrows : false,
padding: 0,
overlay: {
locked: false
},
onClosed: function() {
location.reload();
}
});
According to the API there is no beforeClose
event, but there is onClose
根据 API 没有beforeClose
事件,但是有onClose