Is there a default option to close a jQuery dialog by clicking somewhere on the screen instead of the close icon?
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
In some cases, Jason's answer is overkill. And
$('.ui-widget-overlay').click(function(){ $("#dialog").dialog("close"); });
doesn't always work with dynamic content.The solution that I find works in all cases is:
Here are 3 methods to close a jquery UI dialog when clicking outside popin:
If the dialog is modal/has background overlay: http://jsfiddle.net/jasonday/6FGqN/
If dialog is non-modal Method 1: http://jsfiddle.net/jasonday/xpkFf/
Non-Modal dialog Method 2: http://jsfiddle.net/jasonday/eccKr/
When creating a JQuery Dialog window, JQuery inserts a ui-widget-overlay class. If you bind a click function to that class to close the dialog, it should provide the functionality you are looking for.
Code will be something like this (untested):
Edit: The following has been tested for Kendo as well:
This post may help:
http://www.jensbits.com/2010/06/16/jquery-modal-dialog-close-on-overlay-click/
See also How to close a jQuery UI modal dialog by clicking outside the area covered by the box? for explanation of when and how to apply
overlay
click or live event depending on how you are using dialog on page.Try this:
Facing the same problem, I have created a small plugin that enables to close a dialog when clicking outside of it whether it a modal or non-modal dialog. It supports one or multiple dialogs on the same page.
More information on my website here: http://www.coheractio.com/blog/closing-jquery-ui-dialog-widget-when-clicking-outside
Laurent