我们有两个html页面。第一页我们正在使用window.open("./pop.html", "",'width=200,height=100');
如何自动提交表格后关闭Html窗口
pop.html
我们正在自动提交表单,我们需要在提交后关闭HTML。代码如下。
<html>
<head>
<script type="text/javascript">
function loadForm() {
var method = "post"; // Set method to post by default if not specified.
var path = "http://localhost:8080";
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "username");
hiddenField.setAttribute("value", "sai");
var passField = document.createElement("input");
passField.setAttribute("type", "hidden");
passField.setAttribute("name", "password");
passField.setAttribute("value", "sai123");
form.appendChild(hiddenField);
form.appendChild(passField);
document.body.appendChild(form);
form.submit();
window.close();
}
</script>
</head>
<body onload="loadForm();">
<form>
</form>
</body>
</html>
但是window.close();
不能在页面中工作。它错过了什么吗?
我认为由于安全问题,这是不可能的。 – Albzi