1

I know there is a lot of topics with this questions, but I don't found the answer to my particular question ...

Refer to the FAQ, we had to use one of these to close the fancybox.

$.fancybox.close();

or

parent.$.fancybox.close();

But this doesn't work in my case.

I use an AJAX type of fancybox, see below :

  $('.fancybox2').fancybox({

            type: 'ajax',
            title: 'Admin',
            maxWidth    : 800,
            maxHeight   : 400,
            fitToView   : false,
            width       : '70%',
            height      : '70%',
            autoSize    : false,
            closeClick  : false,
            openEffect  : 'elastic',
            closeEffect : 'none',
        });

So after the click on a button, it shows another page in the fancybox. In this page there is a button with the following code :

<input type=button onclick="$.fancybox.close();" value="Save" style="margin-top:30px;" class=button>
Jason
  • 2,278
  • 2
  • 17
  • 25

1 Answers1

3

Your onclick="$.fancybox.close();" doesn't see your main fancybox object. Try to do something like this

<input type="button" value="Save" style="margin-top:30px;" class="button closeFancybox">

And in your main document

$(function(){
    $(document).on('click','.closeFancybox',function(){
            $.fancybox.close();
    })
})

Update

Please try to simulate similar behaviour on https://jsfiddle.net I've tried example that you've wrote and it worked.

xAqweRx
  • 1,236
  • 1
  • 10
  • 23