2009-11-13 85 views
0

我創建了一個popupwindow,可以從我的cakephp中打開我的頁面中的一個。 此彈出窗口是鏈接到其他頁面的表單。 一旦你點擊'提交'按鈕,它會自動保存數據到Mysql並關閉它。如何在點擊提交按鈕後關閉我的popupwindow?

我想關閉彈出窗口,一旦點擊提交按鈕。 我設置了top.close();但stil沒有功能。

我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> 
+0

請標記此如JavaScript。 – fserb 2009-11-13 03:22:30

回答

1

window.open()返回新窗口的引用。那麼你可以:

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

function popup(mylink,windowname){ \t \t \t \t if(!window.focus)return true; \t \t \t var href; \t \t if(typeof(mylink)=='string') \t \t \t href = mylink; \t \t else \t \t \t href = mylink.href; my_win = window.open(href,windowname,'width = 800,height = 1200,scrollbars = yes'); \t \t my_win = window.close(); \t \t} 我試着放在window.open後面但是工作。 ÿ? – 2009-11-13 04:14:02

0

如果彈出窗口是包含提交按鈕的窗口,則需要。 「window.close()的;」否則,「var someRef = window.open(); someRef.close()」

-1

如果您正在使用PHP,請執行此操作;這個對我有用。

只需將它放在提交表單下方即可。下面在功能上線

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

寫在那裏的形式提交那張之後

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

和刪除window.close()的從表單onsubmit事件