Close jquery modal dialog from remote page

I use the jQuery-UI dialog widget in a Grails-based application to load a remote page (in this case, a simple file upload form). The deleted page is defined elsewhere in my project and does not know that it is loading in a dialog box.

Is there any way to close the dialog by the link on the remote page? Should I somehow pass a link to the dialog when the page loads, or is there a way to trigger a closing event, while remaining an agnostic of the dialog itself?

0
javascript jquery jquery-ui grails modal-dialog
Oct 29 '09 at 15:04
source share
2 answers

Try this HTML:

<a href="#" id="btnDone">CLOSE</a> 

and this javascript:

 $("#btnDone").click(function (e) { e.preventDefault(); var dialogDiv = $("#btnDone").parents(".ui-dialog-content"); if (dialogDiv.length > 0) { dialogDiv.dialog('close'); } }); 

on your remote page. He will see if he is in the dialog box, and if so, he will close it. If not, he will do nothing.

+1
Nov 10 '09 at 13:48
source share

If you give your dialog a known identifier, you can view it using jquery (for example, $ ('# mydialog') and close it with a script on the remote page. The only problem might be to evaluate JS when the remote page loads in dialog window.

0
Oct 29 '09 at 22:05
source share



All Articles