When a web page uses scripting to close a browser window that was opened by the user and not opened by some action on another page, Internet Explorer pops up a question to the user warning that "The webpage you are viewing is trying to close the tab." (in this case, Internet Explorer 7) and asking the user for permission to close the tab.
Before Internet Explorer 7, all that was needed to do was setting the window.opener property to a non null value:
window.opener = self;
window.close();
Unfortunately, Internet Explorer 7 isn't fooled by this. Internet Explorer 7 knows if the window was opened by the user or not, regardless the value of the window.opener property.
Fortunately, Internet Explorer can still be fooled:
window.open("","_self");
window.close();
Going one step further, if you want all your calls to the window.close method to work this way, you can change the method implementation like in the following example:
<!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>Untitled Page</title>
<script type="text/javascript">
// Save a reference to the original method.
var windowClose = window.close;
// Re-implement window.open
window.close = function ()
{
window.open("","_self");
windowClose();
}
</script>
</head>
<body>
<input type="button" value="Close Me!" onclick="window.close()" />
<input type="button" value="Close Me!" onclick="windowClose()" />
</body>
</html>