0

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?

0

1 Answer 1

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 :)

2
  • 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. Commented Aug 17, 2017 at 16:18
  • So in that case you should follow below thread. - magento.stackexchange.com/questions/174782/… ... thanks Commented Aug 17, 2017 at 16:23

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