【问题标题】:How to close my popupwindow once the submit button click?单击提交按钮后如何关闭我的弹出窗口?
【发布时间】:2009-11-13 03:09:26
【问题描述】:

我创建了一个弹出窗口,它从我的 cakephp 中打开我的 1 个页面。 此弹出窗口是链接到其他页面的表单。 点击“提交”按钮后,它会自动将数据保存到 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>

【问题讨论】:

  • 请将此标记为 javascript。

标签: javascript popupwindow


【解决方案1】:

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

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

【讨论】:

  • function popup(mylink, windowname){ if (!window.focus)return true;变量href; if (typeof(mylink) == 'string') href=mylink;否则href=mylink.href; my_win=window.open(href, windowname, 'width=800,height=1200,scrollbars=yes'); my_win=window.close();我尝试在 window.open 之后放置但 n 工作。是吗?
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    在提交后表单所在的函数中写下一行

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

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

    【讨论】:

      【解决方案4】:

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-01-26
        • 2011-12-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-29
        • 1970-01-01
        相关资源
        最近更新 更多