单击提交按钮后如何关闭弹出窗口?
我创建一个弹出窗口,从我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
window.open() 返回对新窗口的引用。然后你可以:
window.open() returns a reference to the new window. Then you can:
如果弹出窗口是包含提交按钮的窗口,则您需要。 “窗口.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()"
在提交后表单进入的函数中编写以下行
,并从表单 onsubmit 事件中删除 window.close()
write below line in function where form goes after submit
and Remove the window.close() from the form onsubmit event
如果您使用 PHP,只需执行此操作;它对我有用。
只需将其放在提交表单下方即可。
If you're using PHP just do this; it works for me.
Just place this below the submit form.