Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
HTML and CSS
Methods
 close Method
close Method

Closes the current browser window or HTML Application (HTA).

Syntax

object.close()

Return Value

No return value.

Remarks

How a window is closed programmatically determines whether the user is prompted with a confirmation dialog box.

  • Invoking the window.close method on a window not opened with script displays a confirmation dialog box. Using script to close the last running instance of Windows Internet Explorer also opens the confirmation dialog box.
  • Invoking the window.close method on an HTA closes the application without prompting the user because the HTA is trusted and follows a different security model. For more information on the security model of HTAs, please refer to The Power of Trust: HTAs and Security.

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

<SCRIPT LANGUAGE="JScript">
function myClose() {
    close();}
</SCRIPT>
<BODY onclick="myClose();">
Click this page and window.close() is called.
</BODY>

When an event on any object calls the close method, the document.close method is implied.

<BUTTON onclick="close();">
Click this button and document.close() is called.
</BUTTON>

Standards Information

There is no public standard that applies to this method.

Applies To

window, Window Constructor
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
window.close() and xslt      Panayotis.Papapostolou ... Ian from Hobart!   |   Edit   |   Show History
When a window is opened with script and the url contains xml content parsed to html by xslt, the close() command will still fire the confirmation dialog box!

MAG: Is there a workaround for this? How to close a window in this manner on a page parsed by xslt in script without getting the confirmation dialog box?

Yes! You can bypass this bug by replacing the current window with a standard html page that just closes itself: eg, in your xslt transfromed page instead of self.close() use window.open('ieclose.htm','_self');

ieclose.htm looks like:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="-1" />
<title>closing</title>
</head>
<body onload="self.close()">
</body>
</html>

You can also try:
window.open('','_self');window.close();

It worked for me.
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker