问题
I'm having a problem using the fancybox API after Close.
I open the function when people click on this:
<a class="fancybox fancybox.iframe btn" href="myurl.php"></a>
The javascript behind this is:
$('.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 !
回答1:
Some clarification to avoid further confusion:
Based on your 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
class tells fancybox the type of content it should handle, but you don't use it to bind the selector to fancybox.
See JSFIDDLE
NOTE : this is for fancybox v2.x
回答2:
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)
回答3:
Try using onClose
event:
$('.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
http://fancybox.net/api
来源:https://stackoverflow.com/questions/25884088/fancybox-afterclose-event-not-working