Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery-ui-dialog - How to hook into dialog close event

I am using the jquery-ui-dialog plugin

I am looking for way to refresh the page when in some circumstances when the dialog is closed.

Is there a way to capture a close event from the dialog?

I know I can run code when the close button is clicked but that doesn't cover the user closing with escape or the x in the top right corner.

like image 538
Brownie Avatar asked Oct 05 '08 12:10

Brownie


People also ask

How do you close a dialog box in HTML?

The close() method closes the dialog. Tip: This method is often used together with the show() method.


2 Answers

I have found it!

You can catch the close event using the following code:

 $('div#popup_content').on('dialogclose', function(event) {      alert('closed');  }); 

Obviously I can replace the alert with whatever I need to do.
Edit: As of Jquery 1.7, the bind() has become on()

like image 143
Brownie Avatar answered Oct 18 '22 04:10

Brownie


I believe you can also do it while creating the dialog (copied from a project I did):

dialog = $('#dialog').dialog({     modal: true,     autoOpen: false,     width: 700,     height: 500,     minWidth: 700,     minHeight: 500,     position: ["center", 200],     close: CloseFunction,     overlay: {         opacity: 0.5,         background: "black"     } }); 

Note close: CloseFunction

like image 45
Darryl Hein Avatar answered Oct 18 '22 04:10

Darryl Hein