单击提交按钮后如何关闭弹出窗口?

时间:2009-11-13 03:09:26

标签: javascript popupwindow

我创建了一个弹出窗口,从我的cakephp中打开我的一个页面。 此弹出窗口是链接到其他页面的表单。 点击“提交”按钮后,它会自动将数据保存到Mysql并关闭它。

我想在点击提交按钮后关闭弹出窗口。 我设置top.close();但是没有任何功能。

我在想什么..

<script type="text/javascript">

    function popup(mylink, windowname){
    if (! window.focus)return true;
        var href;
    if (typeof(mylink) == 'string')
        href=mylink;
    else
        href=mylink.href;
    window.open(href, windowname, 'width=800,height=1200,scrollbars=yes');
    return false;
    }
    </script>   
    <p><A HREF="http://.../index.php/products/add" onClick="return popup(this, 'notes');top.close();">Add Products</A></p>

4 个答案:

答案 0 :(得分:1)

window.open()返回对新窗口的引用。然后你可以:

my_win = window.open(...);
[...]
my_win.close();

答案 1 :(得分:0)

如果弹出窗口是包含提交按钮的窗口,则需要。 “window.close()的;”否则,“var someRef = window.open(); someRef.close()”

答案 2 :(得分:0)

在提交

之后的表单中写下函数
echo "<script>window.close();</script>";

并从onsubmit事件

中的表单中删除window.close()

答案 3 :(得分:-1)

如果您正在使用PHP,请执行此操作;它对我有用。

只需将其放在提交表单下方即可。

<?php
$close = 1;
if ($close) {
    echo '<body onunload="self.close()">';
}