Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing all jquery dialog windows in JavaScript

How does one close all jquery ui dialog windows in javascript?

Situation:

The page has multiple things that can be opened using the dialog boxes. I need a way to close all previous windows before opening a new one.

like image 979
Matthew Rygiel Avatar asked Oct 07 '10 18:10

Matthew Rygiel


People also ask

How to close a dialog box in JavaScript?

Close Dialog when clicking outside of its region in JavaScript Dialog control. By default, dialog can be closed by pressing Esc key and clicking the close icon on the right of dialog header. It can also be closed by clicking outside of the dialog using hide method.

How to close modal dialog box in JavaScript?

You can also use JavaScript hide method. Click the button to launch the modal. Then click on the backdrop, close icon or close button to close the modal.

What is closeclose () event in jQuery UI dialog?

close ( event, ui ) : Triggers when we click on close button in the dialog. There is callback function attached to this close. How to remove close button from jQuery UI dialog using jQuery ?

How to close a window using JavaScript?

However, we can close a window by using a workaround. The approach to be followed is by opening the current URL using JavaScript so that it could be closed with a script. Step 1: Opening a new window using the open () method: First we need to open a new window using the window.open () method.

How to close a textarea in a dialog using JavaScript?

‘Open Dialog’ button will trigger the click function (#gfg) that will further open the <textarea> in a dialog (#gfg2). close ( event, ui ) : Triggers when we click on close button in the dialog. There is callback function attached to this close.

What's new in jQuery UI CLOSE?

What's New ? jQuery UI Close event is triggered when the dialog box is closed. Learn more about jQuery selectors and events here. First, add jQuery Mobile scripts needed for your project.


2 Answers

They all have the .ui-dialog-content class, so select by that and close them, like this:

$(".ui-dialog-content").dialog("close"); 
like image 82
Nick Craver Avatar answered Sep 26 '22 02:09

Nick Craver


Be careful with the above. If you define a close method for your dialog, it will get fired even if the dialog is not open. This was a huge issue in an Angular project where we were manually calling $apply() in our dialog close method. Another event was trying to close all dialogs on the screen and our close method was called even though wasn't open resulting in a digest issue.

like image 36
user3899909 Avatar answered Sep 26 '22 02:09

user3899909