Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Edit: Here's a plugin I authored that extends the jQuery UI Dialog to include closing when clicking outside plus other features: <a href="https://github.com/jasonday/jQuery-UI-Dialog-extended" rel="noreferrer">https://github.com/jasonday/jQuery-UI-Dialog-extended</a></p> </blockquote> <p>Here are 3 methods to close a jquery UI dialog when clicking outside popin:</p> <p>If the dialog is modal/has background overlay: <a href="http://jsfiddle.net/jasonday/6FGqN/" rel="noreferrer">http://jsfiddle.net/jasonday/6FGqN/</a></p> <pre><code>jQuery(document).ready(function() { jQuery("#dialog").dialog({ bgiframe: true, autoOpen: false, height: 100, modal: true, open: function() { jQuery('.ui-widget-overlay').bind('click', function() { jQuery('#dialog').dialog('close'); }) } }); }); </code></pre> <p>If dialog is non-modal Method 1: <a href="http://jsfiddle.net/jasonday/xpkFf/" rel="noreferrer">http://jsfiddle.net/jasonday/xpkFf/</a></p> <pre><code>// Close Pop-in If the user clicks anywhere else on the page jQuery('body') .bind('click', function(e) { if(jQuery('#dialog').dialog('isOpen') &amp;&amp; !jQuery(e.target).is('.ui-dialog, a') &amp;&amp; !jQuery(e.target).closest('.ui-dialog').length ) { jQuery('#dialog').dialog('close'); } }); </code></pre> <p>Non-Modal dialog Method 2: <a href="http://jsfiddle.net/jasonday/eccKr/" rel="noreferrer">http://jsfiddle.net/jasonday/eccKr/</a></p> <pre><code>$(function() { $('#dialog').dialog({ autoOpen: false, minHeight: 100, width: 342, draggable: true, resizable: false, modal: false, closeText: 'Close', open: function() { closedialog = 1; $(document).bind('click', overlayclickclose); }, focus: function() { closedialog = 0; }, close: function() { $(document).unbind('click'); } }); $('#linkID').click(function() { $('#dialog').dialog('open'); closedialog = 0; }); var closedialog; function overlayclickclose() { if (closedialog) { $('#dialog').dialog('close'); } //set to one because click on dialog box sets to zero closedialog = 1; } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload