jQuery iframe modal close on form submit works partially
I have a jQuery Modal dialog with an iframe in it, the iframe includes a form. When a user submits the form, I would like to close down the modal dialog.
I managed to do that by adding the last bit of code written in this question, but the problem is that it closes the dialog only once, if I open it again and attempt to close it, it doesn't work.
jquery modal script on index.开发者_Go百科php:
<script type="text/javascript">
function showRegDialog(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>
link on index.php to call showRegDialog modal:
<a href="javascript:showRegDialog('/register.php');">Register now</a>
This is the content of the register.php
<html>
<body>
<form action="" method="POST" onsubmit="parent.closeModal();">
<input type="text">
<input type="submit">
</form>
</body>
</html>
I've added this to index.php:
function closeModal() {
$("#externalSite").dialog("close");
}
Can you try for your index.php
function closeModal() {
$("#externalSite").dialog("destroy");
}
精彩评论