views:

2835

answers:

4

I'm using the Fancybox plugin for my modal windows. It seems like no matter what options I use I can't prevent the fancybox modal window from closing when the user clicks outside of the fancybox modal window (grayed out area).

Is there a way to force the user to click the X or a button that I trigger the close event? This seems like it should be simple so I'm hoping I'm just reading the examples wrong.

I've tried hideOnContentClick: false but that doesn't seem to be working for me. Any ideas?

+2  A: 

There is no option for that. You will have to change the source code.

In jquery.fancybox-1.2.1.js you need to comment out (or delete) line 341 in the _finish method:

//$("#fancy_overlay, #fancy_close").bind("click", $.fn.fancybox.close);
Scott Dowding
Excellent. I commented the line out and added:$("#fancy_close).bind("click", $.fn.fancybox.close);This does exactly what I need. Thanks!
Mike
+1  A: 

Just add following line to your function, you do not have to change anything in jquery.fancybox-1.2.6.js

callbackOnStart : function() {$("#fancy_overlay").bind("click","null");},

Raj Gohil
We only wanted this behavior on one of our fancy boxes so changing the source wasn't an option, Thanks!
spilliton
Just discovered that this doesn't work on Google Chrome, haven't figured out why yet.
spilliton
A: 

I am using fancybox 1.2.6 and as told above i tried both the ways to avoid closing of fancybox when you click on the outside of the content.. But nothing is working.. can you help me with this.. and one more thing.. i am trying to trigger the fancybox close function when you submit a form..How can i do that ?

AquaGirl
A: 

I'm using fancybox 1.3.1, if you wanna force the user to close the modal box ONLY by clicking on the button, you can specify in the configuration:

<script type="text/javascript">
  $(document).ready(function() {
    $("#your_link").fancybox({
      'hideOnOverlayClick':false,
      'hideOnContentClick':false
    });
  });
</script>
justinw