close method
[This documentation is preliminary and is subject to change.]
Closes the current browser window or HTML Application (HTA).
Closes the current window.
Syntax
var retval = window.close();Standards information
There are no standards that apply here.
Parameters
This method has no parameters.
Return value
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
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.
Invoking the window.close method on a Metro style app using JavaScript closes the window without prompting the user. The last window to close closes the application.
Build date: 3/8/2012
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.
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");
- 5/23/2008
- Panayotis.Papapostolou
- 4/1/2011
- Scott Trenda