1

I have a jquery fancybox with a normal a href link inside it. When I click on that link the fancybox closes. How can I prevent the fancybox to close after I clicked on the link?

This is the code for the fancybox:

$(function(){
    $(".booking_module").fancybox({
        maxWidth    : 550,
        topRatio    : 0,
        fitToView   : false,
        width       : '100%',
        height      : 'auto',
        autoSize    : false,
        closeClick  : false,
        openEffect  : 'none',
        closeEffect : 'none',
        centerOnScroll: true, 
        autoResize: true,
        autoCenter: true,
        margin : [topmargin, 0, 0, 0],
        helpers : { 
        overlay : {closeClick: false}
        }
    });
});
BastiaanWW
  • 1,259
  • 4
  • 18
  • 34

2 Answers2

2

This option will disable closing fancybox when clicking on the background

$(document).ready(function() {
   $(".booking_module").fancybox({
        helpers : { 
            overlay : {
                closeClick: false
            } // prevents closing when clicking OUTSIDE fancybox
        }
   }); 
});

and this option will disable all default click methods of closing fancybox

 $(document).ready(function() {
    $(".booking_module").fancybox({
        closeBtn : false,
        closeClick : false,
        helpers : { 
            overlay : {
                closeClick: false
            } // prevents closing when clicking OUTSIDE fancybox
        },
        keys : {
            close: null
        } // prevents close when clicking escape button
    });
});

i think the second option is what you're looking for. Maybe without the "closeBtn"

  • thanks for your answer. I found the problem was in something else. See below. As to why doesn't make sense to me, but removing only this class did the job. – BastiaanWW Feb 24 '15 at 20:32
  • copy/paste from another answer seems OK when referring the source http://stackoverflow.com/a/8404587/1055987 :P – JFK Feb 24 '15 at 23:01
0

The problem was that I was using 3 classes for the a href. One of those classes was not used anymore. When I removed that un-used class it didn't close anymore after clicking on that link.

BastiaanWW
  • 1,259
  • 4
  • 18
  • 34