How can I detect that the (X) close button of a jQuery UI Dialog was clicked, separately from the dialogclose/dialogbeforeclose events?

前端 未结 4 1121
遇见更好的自我
遇见更好的自我 2021-02-19 07:43

I\'d like to be able to detect the (x) close button of a jQuery UI Dialogue being clicked, but I don\'t want to use the dialogclose / dialogbeforeclose

4条回答
  •  借酒劲吻你
    2021-02-19 08:19

    I know this is an old question, and the OP said he didn't want to use beforeClose, but the reason was because it always fires, even for things other than the X. However, I noticed that the techniques here don't allow me to prevent a dialog from closing (I want a confirm window to open if there are unsaved changes). If we Ithe techniques here, use beforeClose, we can achieve the desired result, but make it cancellable. I used:

    beforeClose: function (e, ui) {
        if ($(e.currentTarget).hasClass('ui-dialog-titlebar-close') && whateverMyConditionIs)
            e.preventDefault();
    }
    

    Thought it might help someone else!

提交回复
热议问题