views:

204

answers:

5

I have a simple popup (not an Iframe) where a user can send mail to each other. There is a submit button to send the information and a cancel button which should close the overlay.

I do have some trouble getting the close button to work.

The code looks like this:

<asp:Button runat="server" ID="btnCancel" Text="Cancel" />

<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery("#<%= btnCancel.ClientID %>").click(function () {
            jQuery.colorbox.close(); return false;
        });
    });
</script>

I have tried with both parent.jQuery.colorbox.close(), jQuery.fn.colorbox.close() but with no success.

+1  A: 

Does your colorbox have a close button at the top. [close]. In my application when i want to introduce a cancel button to close the colorbox window from a link other than already provided by colorbox.

I do a workaround like.

jQuery('#cboxClose').click();

this will click the default close button and will eventually close the colorbox.

sushil bharwani
I do have a close box in the bottom with the id 'cboxClose', and I liked the idea but it didn't work.
Dofs
can you tell me what exactly you did. I have been doing this colorbox closing from quite a while. And have used it extensilvely can you show some code.
sushil bharwani
I replaced 'jQuery.colorbox.close();' with 'jQuery('#cboxClose').click();'
Dofs
A: 

Did you try to use

$.fn.colorbox.close(); 

instead of

jQuery.colorbox.close();

?

Maybe, you already did this:

 $("#cboxClose").click(function(){
      $.fn.colorbox.close();});

You must not have the problem on closing the colorbox. Actually, I also have a colorbox in an app with a cancel button and that close button which looks like an image. There's no problem at all.

jean27
Yes, and it didn't work.
Dofs
A: 

You can use:

$(window).colorbox.close();
Ioannis Karadimas
It didn't work.
Dofs
A: 

I found out that I was adding jQuery and colorbox twice, since it was loaded both in the frame and the on the page calling colorbox.

It worked after I removed jQuery and Colorbox from the overlay page, so it only got included.

I used 'sushil bharwani' idea, and executed the close event.

Dofs
A: 

I think you missing or mistake small thing in your code. Otherwise close method will work as expected. Have you check first that your button click fire or not? If fire, Have you got any JS error?

Mayur bhalgama