1

So I've tried using all the solutions that is available on the internet, but doesn't seem to work for some reason.

I'm using (or the project, rather) fancybox-1.3.4, and other than the close icon, a link needs to be used to close the pop-up.

enter image description here

<a id="kpitilepoplink" href="#kpitilepop">Trigger pop-up</a>

<div style="display:none;">
    <div id="kpitilepop" class="newpopupcontainer">
    Contents
    <a href="#" id="popcloselink" class="blu-btn">Close</a>
    </div>
</div>

<script type="text/javascript">
     $(document).ready(function () {                                    
         $("a#kpitilepoplink").fancybox({
         }); 
     });                                     
</script> 
<script type="text/javascript">
     $(document).ready(function(){
         $('#popcloselink').click(function(){                                       
         alert();
         $(this).fancybox.close();
         });
     });
</script> 

The solutions available on the internet is not working, and i'm getting fancybox.close is not a function error in the browser console

Sagar Raj
  • 909
  • 3
  • 14
  • 34

3 Answers3

2

The documentation has the following method

$.fancybox.close();

Make sure you prevent the default click event

another solution will be to trigger the x close button

 $("a.fancybox-close").trigger("click"); 
madalinivascu
  • 32,064
  • 4
  • 39
  • 55
1

Just a tip: if you are using fancyBox3, your could simply add data-fancybox-closeto any element and clicking it will close current fancyBox instance.

For example:

$.fancybox.open('<div><p>Hello! This is fancyBox!</p><p><a href="javascript:;" data-fancybox-close>Close</a></p></div>');
Janis
  • 8,593
  • 1
  • 21
  • 27
0

Suppose you want to close it on click of "Close" button //popcloselink is the id of your close button.

$('#popcloselink').click(function(){
   $.fancybox.close();
});
IamDD
  • 1
  • 1