Bootbox: Callback function after dismissing the dialog / Clicking on the 'X' button

Null Reference picture Null Reference · Mar 18, 2015 · Viewed 30.3k times · Source

The following snippet allows me to perform stuff in a callback function for the buttons that are clicked. However, how can I get a callback function, or a similar workaround such that I can perform some code when a user clicks on the 'X' button/dismisses the dialog?

    bootbox.dialog({
        title: "Woah this acts like an alert",
        message: "Cool info for you. You MUST click Ok.",
        buttons: {
            sucess:{
                label: "Ok",
                callback: callback
            }
        }       
    });

   callback(){//stuff that happens when they click Ok.}

I do not want to disable/hide the close button with

closeButton: false,

Answer

Haris ur Rehman picture Haris ur Rehman · Jun 25, 2015

There is onEscape function for this.

bootbox.dialog({
    message: 'the msg',
    title: "Title",
    onEscape: function() {
        // you can do anything here you want when the user dismisses dialog
    }
});