Two lines of script close the current IE7 browser window or tab without any confirmation prompt. The trick is calling window.open("","_self") first, which reassigns the window’s navigation target to itself, then immediately calling window.close().
<!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><title>IE7 Close Window without Prompt</title></head>
<body>
<font face="Tahoma" size="2">
<b> IE7 ONLY </b><br /><br />
Simple Window close with no prompts at all. Click <input type="button" value="Here" onclick="closeWindow()"> to close this window.
<br />
If the window has more than one tab, it will just close the current one.
<br /><br />
<hr />
<font face="MonoSpace">
window.open("","_self");<br />
window.close();
</font>
<hr />
</font>
<script language="JavaScript">
function closeWindow()
{
window.open("","_self");
window.close();
}
</script>
</body>
</html>
Normally IE7 shows a confirmation dialog when a script tries to close a window that wasn’t opened by script. Navigating the window to itself with window.open("","_self") first appears to change its internal “was opened by script” state, making the subsequent window.close() proceed silently.
Found during my years at Microsoft (2006–2014). These bugs were patched long ago — shared here as a historical record for learning purposes.
Read other posts