views:

397

answers:

2

hi.

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>
+1  A: 

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

my_win = window.open(...);
[...]
my_win.close();
fserb
function popup(mylink, windowname){ if (! window.focus)return true; var href; if (typeof(mylink) == 'string') href=mylink; else href=mylink.href; my_win=window.open(href, windowname, 'width=800,height=1200,scrollbars=yes'); my_win=window.close(); }i try put after the window.open but n work. y?
JaYwZx
A: 

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