首页 > 解决方案 > How to close browser window after form submission is complete?

问题描述

I have old file that has been changed. One of the requests for this file/project modification is when user clicks OK to submit the form and close the current browser window. I'm wondering if this can be achieved with plain/vanilla JavaScript? So I have form and button:

<form name="test" id="test" action="/save_form.cfm">
   <input type="submit" value="OK">
</form>

标签: javascriptbrowserform-submit

解决方案


您可以简单地使用:

window.close();

每当单击按钮时,您都可以在输入标签中键入它或使用该代码制作一个新的脚本标签。

例如

<input type="submit" value="OK" onclick="closeWindow();">

此外,您可以将 return false 添加到 'onclick' 以防止默认操作。


推荐阅读