onbeforeunload doesn't work properly in HTA

Discussion in 'Internet Explorer' started by David Mayerovitch, Dec 20, 2006.

  1. I want to prevent the user from accidentally exiting an HTA. When any
    attempt to close the application is made (such as clicking on the close
    button), a dialog should appear asking the user to confirm the exit. If the
    user clicks OK, the application closes; if the user clicks Cancel, the
    application remains open.

    I wanted to do this using the onbeforeunload event, and wrote the following
    HTA as a test. But the app always closes whether the user clicks OK or
    Cancel.

    When I rename the file from Test.hta to Test.htm and run it in IE (and
    allowing blocked content), the file operates as intended and allows the user
    to cancel the exit.

    Can anyone explain why this method works for *.htm and not for *.hta? And
    can anyone suggest a way of accomplishing this in an HTA?

    Thanks.
    David

    The code:

    -------------------------------------------------------------
    <html>
    <title>Click the close button</title><head>
    <hta:application
    id=""
    applicationname="" version="1.0"
    icon="" windowstate="normal" navigable="yes"
    singleinstance="no" showintaskbar="yes"
    sysmenu="yes" caption="yes"
    border="thick" borderstyle="complex" innerborder="yes"
    maximizebutton="yes" minimizebutton="yes"
    scroll="no" contextMenu="yes"
    </hta:application>

    <script href="" type="text/javascript">

    window.onbeforeunload=askQuit;

    function askQuit(){
    return("Really quit?");
    }

    </script>
    </head>

    <body>
    </body>

    </html>
    -------------------------------------------------------------
     
    David Mayerovitch, Dec 20, 2006
    #1
    1. Advertisements


  2. Try the IE web developer forum

    http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=923&SiteID=1


    Otherwise my guess would be that HTA implies a different security zone
    and you're seeing an effect from that.


    HTH

    Robert Aldwinckle
    ---
     
    Robert Aldwinckle, Dec 22, 2006
    #2
    1. Advertisements

  3. Thanks, Robert. I've done as you suggested.

    David
     
    David Mayerovitch, Dec 23, 2006
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.