JavaScript Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Java-Script Tutorial
Introduction Introduction
Variables Variables
Operators Operators
Statements Statements
Loops Loops
Functions Functions
Objects Objects
Arrays Arrays
Cookies JS Cookies
Browser Objects Browser Objects
Form DOM Form DOM
Style Objects DOM Style Objects
Forums Ask Your Doubts
Scraps More about Javascript
Feedback Feedback
 




Window Close Function


Tutorials Javascript

Topic

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>





A Note
Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script. Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.

Other Links

web hosting