Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close a jQuery UI modal dialog by clicking outside the area covered by the box?

I am using jQuery 1.6 and jQuery UI. I successfully implemented a modal dialog window which width is almost 50% of my application web page' width. I would like to give to the user another way to close the dialog so that when he\she clicks outside the area covered on the page by the "modal box", this one will be closed as if the user clicked on the "standard" "x" button on the top-right of that.

How can I do that?

like image 509
Backo Avatar asked Sep 09 '11 23:09

Backo


People also ask

How do you close a dialog box by clicking outside?

It can also be closed by clicking outside of the dialog using hide method. Set the CloseOnEscape property value to false to prevent closing of the dialog when pressing Esc key. In the following sample, dialog is closed when clicking outside the dialog area using hide method.

How do I turn off modal dialog?

There are few ways to close modal in Bootstrap: click on a backdrop, close icon, or close button. 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.


1 Answers

You have two options for the close model dialog box

$('#your-dialog-id').modal('toggle');

OR

you can use the click event directly when you click outside box

$("#your-dialog-id .close").click()
like image 123
Nikunj K. Avatar answered Oct 07 '22 11:10

Nikunj K.