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.

An HTML application that uses the "onbeforeunload" event closes unexpectedly in Internet Explorer 7 when you click "Cancel"


View products that this article applies to.

Symptoms

Consider the following scenario:
  • You create an HTML application (HTA).
  • The HTA uses the onbeforeunload event.
  • You start the HTA in Windows Internet Explorer 7.
  • When you close the HTA, you receive a message that resembles the following:
    Are you sure you want to navigate away from this page?

    string value

    Press OK to continue, or Cancel to stay on the current page.
    Note In this message, the placeholder string value represents the value of the event.returnValue property in the code for the HTA.
In this scenario, the HTA closes as expected when you click OK. However, the HTA closes unexpectedly when you click Cancel.

↑ Back to the top


Cause

This issue occurs because of how the Shdocvw.dll file handles the IOleCommandTarget::Exec method.

↑ 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

This problem does not occur when you start the HTA in Microsoft Internet Explorer 6.

↑ Back to the top


Steps to reproduce the problem

  1. Create an HTA.
  2. Insert the following code into the HTA:
    <html>

    <head>
    <TITLE>TEST</TITLE>
    <HTA:APPLICATION ID="TEST"
    APPLICATIONNAME="TEST"
    BORDER="thick"
    BORDERSTYLE="normal"
    CAPTION="yes"
    CONTEXTMENU="no"
    MAXIMIZEBUTTON="no"
    MINIMIZEBUTTON="yes"
    SELECTION="no"
    SHOWINTASKBAR="yes"
    SINGLEINSTANCE="yes"
    SYSMENU="yes"
    VERSION="1.0"
    WINDOWSTATE="normal"/>

    <script type="text/javascript">
    function closeIt()
    {
    event.returnValue = "string value"; // Any string value here forces a dialog box to appear before the window closes.
    }
    </script>
    </head>

    <body onbeforeunload="closeIt()">

    <a href="http://www.microsoft.com">Click here to navigate to www.microsoft.com </a>

    </body>

    </html>
  3. In Internet Explorer 7, start the HTA.
  4. Close the HTA.
  5. Click Cancel. Notice that the window closes.

↑ Back to the top


References

For more information about HTAs, visit the following Microsoft Developer Network (MSDN) Web site:For more information about the event.returnValue property, visit the following MSDN Web site:

↑ Back to the top


Keywords: consumerie9track, kbentirenet, kbtshoot, kbcode, kbbug, kb

↑ Back to the top

Article Info
Article ID : 946214
Revision : 1
Created on : 1/7/2017
Published on : 9/22/2011
Exists online : False
Views : 426