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

发布于 2024-08-10 21:19:10 字数 679 浏览 1 评论 0原文

我创建一个弹出窗口,从我的 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>

i create a popupwindow which open 1 of my pages from my cakephp.
This popup is a form which link to other page.
Upon u click the 'Submit' button, it wil auto save the data to Mysql and close it.

I would like to close the popup window once the click submit button.
i set top.close(); but stil no function.

What i mising..

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

雨落星ぅ辰 2024-08-17 21:19:10

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

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

window.open() returns a reference to the new window. Then you can:

my_win = window.open(...);
[...]
my_win.close();
陌路黄昏 2024-08-17 21:19:10

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

if the popup is the window that contains the submit button, you need. "window.close();" Otherwise, "var someRef=window.open();someRef.close()"

雨落星ぅ辰 2024-08-17 21:19:10

在提交后表单进入的函数中编写以下行

echo "<script>window.close();</script>";

,并从表单 onsubmit 事件中删除 window.close()

write below line in function where form goes after submit

echo "<script>window.close();</script>";

and Remove the window.close() from the form onsubmit event

假扮的天使 2024-08-17 21:19:10

如果您使用 PHP,只需执行此操作;它对我有用。

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

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

If you're using PHP just do this; it works for me.

Just place this below the submit form.

<?php
$close = 1;
if ($close) {
    echo '<body onunload="self.close()">';
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文