I have a dialog modal box using jQuery’s Dialog UI plugin. I’m trying to detect if the user closed the box using the ‘X’ button in the upper-right corner of the titlebar but have had no luck. I’ve tried:
$('.myModal').dialog({
title: 'dialog 1',
beforeClose: function(){
//do something
}
}).dialog("open");
This will execute the function regardless of user action. i.e. if the user clicks “OK” instead of the ‘X’ button.
I’ve looked through the dialog documentation and can’t find an event, method, or option that gives me the results I’m looking for. Any ideas would be much appreciated.
You need to include the two optional arguments for the beforeClose callback function.
You need to check the event and/or ui variables and figure out if the ‘X’ was pressed or not.