colorbox bug - close colorbox from a link or button

Aximili picture Aximili · May 2, 2012 · Viewed 26.7k times · Source

I open the popup by calling

$.colorbox({ href: "notification.aspx" });

In notification.aspx I have

<script type="text/javascript" src="/scripts/colorbox/jquery.colorbox-min.js"></script>
...
<a id="btnClose">OK</a>

The popup was shown fine, but when I click the button it gives a JavaScript error.

In the main page's javascript I have

$('#btnClose').live('click', function () {
  alert('closing...'); // Alert shown as expected
  $.colorbox.close(); // Nothing happens, no JavaScript error
  //$.fn.colorbox.close(); // same
  //parent.$.fn.colorbox.close(); // same
  //$.colorbox.remove(); // same
  //$('#cboxClose').click(); // same
  //$('#cboxOverlay').click(); // same
});

I am just trying to close the popup.

What am I missing? Thanks in advance.

EDIT: I got it working somehow, I'll find out what made it works.

Answer

Jack picture Jack · May 4, 2012

$.colorbox.close() is the correct way to close colorbox, do not listen to these other comments. The problem is that you are loading colorbox a second time. Remove the jquery.colorbox.js script block from notification.aspx.