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

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>

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.

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 ... Scott Trenda   |   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:

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

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

It worked for me.

SCOTT:
Here's a clever one-line workaround (a combination of the two above items) that I've been using for years:
window.open("javascript:'<script>window.close()</script>'", "_self");
...      davea0511   |   Edit   |   Show History
...
Tags What's this?: Add a tag
Flag as ContentBug
META tag Refresh Method      davea0511   |   Edit   |   Show History
META tag Refresh Method

none of the above methods worked for me,
but success if I did a:

<META
HTTP-EQUIV="Refresh"
CONTENT="1; URL=webclose.html">

...and then created webclose.html:
<!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>

...go figure. I'm guessing the 1 sec delay lets the client browser better assimilate the requested windows management.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker