javascript - 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>
解决方案
您可以简单地使用:
window.close();
每当单击按钮时,您都可以在输入标签中键入它或使用该代码制作一个新的脚本标签。
例如
<input type="submit" value="OK" onclick="closeWindow();">
此外,您可以将 return false 添加到 'onclick' 以防止默认操作。
推荐阅读
- javascript - 如何在不点击的情况下提交输入
- react-native - 有多少包有 React-Native
- huggingface-transformers - HuggingFace Hub 中的 Facebook DETR resnet 50
- python - 从 api 保存到 s3 存储桶
- php - PHP - 转换对象后Json为空
- python - 为什么我的 Treeview 对象返回其项目的值之一而没有下划线?
- powershell - Grafana API 脚本创建新数据源失败
- python - argparse 库:PythonShell.py:错误:无法识别的参数
- routes - 除了上面的请求 DTO,有没有办法在其他地方声明路由?
- r - RM 功能不断出现在控制台上