Confirm Close Colorbox

I want to show a simple confirmation popup if the user tries to close the colorbox. I tried this code:

onCleanup:function(){ confirm('Are you sure'); }

It displays a confirmation window, but the colorbox closes even if I click Cancel!

Can anybody help?

+3
source share
4 answers

I do not know if colorbox allows to cancel closing after its launch.

If that were the case, you would need to change your code to

onCleanup:function(){ return confirm('Are you sure'); }
0
source

The colorbox FAQ section has

You need to override the close color colorbox method:

var originalClose = $.colorbox.close;
$.colorbox.close = function(){
  if (confirm('Do you want to close this window?')) {
    originalClose();
  }
};
+8
source

- FancyBox. , , ColorBox:

onComplete:function(){
  $("#cboxClose").click(function(e) {
    // stop any other script from firing
    e.stopPropagation(); 
    if (confirm('Are you sure')) {
      $.colorbox.close();
      // ensure that the binding is removed when closed
      $("#cboxClose").unbind();
    }
  });
}
+5

@Ken, your example worked fine for me ... almost. The only modification I had to do was unlink before setting the click function, because for some reason it would ignore the if statement and still close on first boot. Below is what I used to confirm when closing colorbox

$(".Add").colorbox({
    onComplete:function(e){
       $("#modalForm").ajaxForm(modalOptions);
       $("#cboxClose").unbind(); 
       $("#cboxClose").click(function(e){
          e.stopPropagation();
          if(confirm('Are you sure you want to cancel your changes?')){
             $.colorbox.close();
             $("#cboxClose").unbind();                               
          }                           
       }); 
    }
   });
+5
source

Source: https://habr.com/ru/post/1754014/


All Articles