I am trying to close parent window from child window using javascript, but its not going to work.
Please share me code if you have any.
My parent html :
<script>
var winr;
var selfw;
function openAn(){
selfw=self.window;
winr=window.open("shell.htm","");
}
function justClose(){
//setTimeout("closeAfterMin()",2000);
winr.close();
}
function closeAfterMin(){
alert("sd");
selfw.close();
}
</script>
<body onload='openAn()' >
<h1>New Web Project Page</h1>
</body>
My Child html :
<script>
function closeAll(){
window.parent.close();
}
</script>
<body>
<div onclick="closeAll();" onunload="window.opener.close();">
Close Parent and self
</div>
</body>
Please help me..
From window.close() MDN:
This method is only allowed to be called for windows that were opened by a script using the window.open method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.
You can close the child window from the parent, but not the other way around.
You might want to try this
window.opener.close()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With