我們有兩個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