最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Magnific Popup Callback when closing - Stack Overflow

programmeradmin8浏览0评论

I am using Magnific Popup for uploading images. When the user clicks or presses the close button, I'd like to get confirmation from the user whether to close on not.

This is my Javascript:

$('#upload').magnificPopup({
    type:'inline',
    callbacks: {
        close: function(){
            if( confirm("Are you sure you want to close?") ) {
              return true;
            }
              return false;
            }
          }
      }
});

But it is not working.

I am using Magnific Popup for uploading images. When the user clicks or presses the close button, I'd like to get confirmation from the user whether to close on not.

This is my Javascript:

$('#upload').magnificPopup({
    type:'inline',
    callbacks: {
        close: function(){
            if( confirm("Are you sure you want to close?") ) {
              return true;
            }
              return false;
            }
          }
      }
});

But it is not working.

Share Improve this question edited Jun 27, 2014 at 18:02 Michael Irigoyen 22.9k18 gold badges91 silver badges132 bronze badges asked Jun 14, 2013 at 5:21 KKKKKK 1,6627 gold badges29 silver badges50 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 11

You can override the close method. By modifying the instance, you will only change the functionality of this specific popup. Then simply call the original close method to finish the job.

$('#upload').magnificPopup({
  type:'inline',
  callbacks: {
    open: function() {
      $.magnificPopup.instance.close = function() {
        // Do whatever else you need to do here
        var confirmed = confirm("Are you sure you want to close?");
        if(!confirmed) {
          return;
        }

        // Call the original close method to close the popup
        $.magnificPopup.proto.close.call(this);
      };
    }
  }
});

You could try:

( '#upload' ).magnificPopup({
    type: 'inline',
    callbacks: {
      close: function(){
         var didConfirm = confirm( "Are you sure?" );
         if( didConfirm == false ){
            return false;
         }
      }
    }
});
发布评论

评论列表(0)

  1. 暂无评论