开发者

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...


I have another solution (the accepted one did not work in my case):

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜