We have two html pages. First Page we are opening the second page using window.open("./pop.html", "",'width=200,height=100');
In the pop.html
we are submitting the form automatically and we need to close the HTML after submission. The code is given below.
<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>
But window.close();
not working in page. Is it missing anything?