Window Close Function

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

Explanation

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();

Example:

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


Ask Questions

Ask Question