asp.net.ph

Skip Navigation Links

close Method

DHTML Methods


Closes the current browser window or HTML Application.

Syntax

window.close ( ) 
Return Value

No return value.

Remarks

Whether the user is alerted before a window is closed programmatically depends on how it is accomplished. When the close method is invoked for a window that was not opened from script, a confirmation dialog box displays for the user.

The same occurs when a script invokes this method to close the last running instance of Microsoft® Internet Explorer. Only for HTML Applications ( HTA ) can the close method be invoked silently. In the case of HTAs, the application is trusted and follows a different security model.

When a function fired by an event on the BODY object calls the close method, the window.close method is implied. When an event on the BODY object calls the close method, the document.close method is implied.

Example

Inserting this code fragment in a document provides a link to close the window of the current document.

<a href="JavaScript:self.close ( ) ">Close</a>

 Show me 

The following example opens a new window and shows use of the close method to close the window object from the window that opened it.

><form>
   <input type="Button" value="Open window"
      onclick="openWin ( )">
   <input type="Button" value="Close window"
      onclick="closeWIn ( )">
</form>

<script language="JavaScript">
<!--
function openWin ( ) {
   theWin = window.open ( "../sample.html", "theWin", "height=300, width=500" );
}

function closeWIn ( ) {
   if ( typeof ( theWin ) == "object" )
      if ( theWin.closed ) alert ( "The window is already closed." );
      else theWin.close ( ) ;
   else alert ( "No window object to close." );
}
//—>
</script>
Applies To

window

See Also

open Method, closed Property, opener Property



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note