简体   繁体   中英

How can I close a jQuery Modal dialog with an iframe in it?

I have a jQuery modal dialog that loads a different page on an iframe.

The iframed page has a form in it and i'm trying to get it to close the jQuery modal dialog automatically after the user submitted the form.

Is that even possible?

Thanks,

LoadModal code (on first.html):

<script type="text/javascript">
function showModal(url) {
$(function() {


var $this = $(this);
var horizontalPadding = 30;
var verticalPadding = 30;
$('<iframe id="externalSite" scrolling="no" frameborder="0" class="externalSite" src="' + url + '" />').dialog({
 title: ($this.attr('title')) ? $this.attr('title') : 'Choose your location',
 autoOpen: true,
 width: 700,
 height: 700,
 modal: true,
 resizable: true,
 autoResize: true,
 overlay: {
  opacity: 0.5,
  background: "black"
 }

}).width(700 - horizontalPadding).height(700 - verticalPadding);            

});
}
</script>
<button onclick="showModal('/iframe.html');">Add</button>

iframe code (iframe.html)

<html>
<body>
<form action="" method="POST">
<input type="text" name="test">
<input type="submit">
</body>
</html>

after iframe form is submitted, I would like to close the dialog opened by first.html jQuery function.

if that means that you want to close the dialog from inside the iframe, you could try something like that

parent.$('#your-dialog-id').dialog('close');

if needed i can provide a complete example later...

我有另一个解决方案(接受的解决方案在我的情况下不起作用):

parent.$('.ui-dialog-titlebar-close').click();

Can you send an example or source code ?

If you can't , try put an achor with target="" attr.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM