jQuery iframe modal close on form submit


November 2018


6k time


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.

How can I do that?

jquery modal script on index.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);            


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

<form action="" method="POST">
<input type="text">
<input type="submit">

2 answers


Вы могли бы искать close

Дайте вашу форму идентификатор.


// function for closing modal window (in parent page)
function closeModal() {

Вызов функции яваскрипта в родительском окне, как это:


положить его в «onsubmit» в вашей форме.