Last updated on March 29th, 2022 at 07:21 am

In this tutorial we are going to see how to open child window from a browser parent and close the same child window using Javascript.

We are assigning a variable named childwin to function and then just use childwin.close() to eventually close the child browser window that got opened from a parent.

<title>Example For Child and Parent Window Operations</title>
<script language="JavaScript">
function closeDep()
if (typeof childwin === 'undefined')
			alert("No Child Window Open")
			alert("Going to close child window")
delete childwin
<body >
<a href="" onclick="childwin='', 'win', 'height=650,width=700'); main='getme';return false">
First CLICK ME ----> Mistonline tutorial world</a></div><p>Now after clicking the above link click this button please
<hr><input type="button" value="Child Window Close" onClick="closeDep();"><br><br>
<a href="">GO BACK TO THE TUTORIAL</a>

Initial check typeof childwin === 'undefined' , we verify if childwin variable is set. ie If a child window is opened.

As you can see above I am adding delete childwin, this is done to unset the variable childwin . Special logic to make sure that after a user click Child Window Close button for the first time to close a window and if they attempt to click on that button again then the script will go back to the initial check where the variable childwin was not set and alert the user with a message No Child Window Open


3 thoughts on “How to open child window from browser parent window using javascript”

Leave a Reply

Your email address will not be published. Required fields are marked *