Window Close Function

How to close the new browser window using javascript?
Code to close a page or window on button click


Object: Window
Method or Function: close()
Closing current window?:
Closing the current page or window is very simple. Just calling close() or this.close() will close the window.
Closing a newly opened window?:
Closing the window that was created or opened by open method. For this we should use the reference that we obtain when the new browser window is created. The procedure is as follows
a) On opening a window, store the return object (window) in a variable
e.g: var xcv = open('url','name');
b) call close function or method on that window object
e.g: xcv.close();


This example will close the window when a button click is done.
<script language=javascript>
function closer()
<form name=xcv>
<input type=button onClick="closer()" value="click to close">

Ask Questions

Ask Question