0

This question already has an answer here:

I have created a modal popup using the modal UI component. See below:

require(
    [
        'jquery',
        'Magento_Ui/js/modal/modal'
    ],
    function(
        $,
        modal
    ) {
        var options = {
            type: 'popup',
            responsive: true,
            innerScroll: false,
            title: 'Modal Title Goes Here',
            buttons: [{
                text: $.mage.__('Continue'),
                click: function () {
                    this.closeModal();
                },
            }]
        };

        var popup = modal(options, $('#modal'));

        $('#modal').modal('openModal');
    }
);

Is there any way that you can detect when the user closes the modal and trigger a function once this event fires?

marked as duplicate by Ben Crook, Prince Patel, liyakat, Siarhey Uchukhlebau, Giel Berkers Aug 21 '17 at 19:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

You can use below code to get your functionality done when modal close.

$('.action-close').click(function(){
    //your code
});

You can see the "action-close" class on close(x) button.

Hope it helps :)

  • Im not sure this would work because this would only trigger if you click on the defined element. I need to trigger a function when the modal is closed as you can close the modal in many different ways e.g. click the close button, click the X button, click outside the modal popup window. – Ryan Copeland Aug 17 '17 at 16:18
  • So in that case you should follow below thread. - magento.stackexchange.com/questions/174782/… ... thanks – Abhishek Panchal Aug 17 '17 at 16:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.