Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

BUG: You cannot close an Internet Explorer window by using the window.setTimeout(window.close,1) method in Windows XP Service Pack 2


Symptoms

When you click a hyperlink that is designed to close a Microsoft Internet Explorer window, the Internet Explorer window does not close. This problem occurs in Microsoft Windows XP Service Pack 2.

↑ Back to the top


Cause

The hyperlink uses the window.setTimeout(window.close,1) method to close the Internet Explorer window.

↑ Back to the top


Workaround

To work around this problem, use the window.setTimeout("window.close()", 1) method or the window.close() method to close the Internet Explorer window.

You can use the following code sample to demonstrate the workaround.
<html>
<body>
<script>
function TimeoutCloseWindow2()
{
window.setTimeout("window.close()", 1);
}
function DirectCloseWindow()
{
window.close();
}
</script>
<p>
<a href="javascript:TimeoutCloseWindow2();">Workaround 1: Click here to try to close the window by using window.setTimeout("window.close()", 1)</a>
</p>
<p>
<a href="javascript:DirectCloseWindow();">Workaround 2: Click here to try to close the window by using window.close()</a>
</p>
</body>
</html>

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

↑ Back to the top


More Information

Steps to reproduce the problem

  1. Click Start, click
    Run, type Notepad, and then click OK.
  2. Put the following code sample in Notepad.
    <html>
    <body>
    <script>
    function TimeoutCloseWindow()
    {
    window.setTimeout(window.close, 1);
    }
    </script>
    <a href="javascript:TimeoutCloseWindow();">Click here to try to close the window by using window.setTimeout(window.close, 1)</a>
    </body>
    </html>
  3. Save the file as Repro.html.
  4. Use Internet Explorer to open the Repro.html file.

    Note If Internet Explorer displays the following message, click the message, and then click Allow Blocked Content.

    To help protect your security, Internet Explorer has restricted this file from showing active content that could access your computer. Click here for options.
  5. Click the Click here to attempt to close window using window.setTimeout(window.close, 1) hyperlink.

    You expect the Internet Explorer window to close. However, the Internet Explorer window does not close.

↑ Back to the top


Keywords: kbtshoot, kbhtml, kbscript, kbwebbrowser, kbbug, kb

↑ Back to the top

Article Info
Article ID : 884768
Revision : 2
Created on : 3/30/2017
Published on : 3/30/2017
Exists online : False
Views : 104