close
Summary
Closes the current browser window or tab, or HTML Application (HTA).
Method of dom/Windowdom/Window
Syntax
window.close();
Return Value
No return value
Examples
<script type="text/javascript">
function closeCurrentWindow()
{
window.close();
}
</script>
Notes
Remarks
When a function fired by an event on any object calls the close method, the window.close method is implied.
<script type="text/javascript">
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 type="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 [_inet_HTML_Applications_Overview#Security#Security The Power of Trust: HTAs and Security].
Using the close method in a Metro style app using JavaScript
Invoking the window.close method on a Metro style app using JavaScript closes the app without prompting the user. It is against Windows Store policy to programmatically close your app. The only time an app should programmatically close is when there is an unrecoverable error, in which case the app should throw an unhandled exception or use the MSApp.terminateApp method. In you use window.close, it appears as a crash to the user is logged as a crash in the developer’s telemetry data on the Windows Store dashboard.
Attributions
Mozilla Developer Network : [window.close Article]
Microsoft Developer Network: [close Method Article]