From: Tom Tyson on
Hi,

I have an HTA in which the user can launch a number of long-running
operations and I need to prevent the user from mistakenly closing the window
while the operations are in progress. I can capture and prevent the Alt-F4
method of closing the window, but the user could still click the X button.

The only method I can think of is using onBeforeUnload, as in

<BODY id="bdy" onBeforeUnload="HandleUnload">

Function HandleUnload()
If bInProgress Then 'global flag that is set to true when processing
begins and false when done
Msgbox "Processing is in progress. Don't try to close the window until
done. ", vbonly, "Warning"
End If

End Function


but I've not found a way to cancel the actual unload event., as
unBeforeUnload does not read a true or false return code, but merely adds
the function return value as a string to a built-in IE dialog.

I've thought of adding a loop to HandleUnload that calls an external
Wscript.sleep script until bInProgress is true.

This would at least make sure that processing is completed before exiting,
but it would still pop up the IE dialog window after processing is done,
which is irritating and unnecessary at that point.

Oh, and hiding the HTA title bar altogether is not an option as i need the
minimize button as well as the application name in the window title bar.

Any ideas ?

Tom


From: Tom Lavedas on
On Aug 26, 8:39 am, "Tom Tyson" <n...(a)spam.org> wrote:
> Hi,
>
> I have an HTA in which the user can launch a number of long-running
> operations and I need to prevent the user from mistakenly closing the window
> while the operations are in progress. I can capture and prevent the Alt-F4
> method of closing the window, but the user could still click the X button..
>
> The only method I can think of is using onBeforeUnload, as in
>
> <BODY id="bdy" onBeforeUnload="HandleUnload">
>
> Function HandleUnload()
>  If bInProgress Then  'global flag that is set to true when processing
> begins and false when done
>    Msgbox "Processing is in progress. Don't try to close the window until
> done. ", vbonly, "Warning"
> End If
>
> End Function
>
> but I've not found a way to cancel the actual unload event., as
> unBeforeUnload does not read a true or false return code, but merely adds
> the function return value as a string to a built-in IE dialog.
>
> I've thought of adding a loop to HandleUnload that calls an external
> Wscript.sleep script until bInProgress is true.
>
> This would at least make sure that processing is completed before exiting,
> but it would still pop up the IE dialog window after processing is done,
> which is irritating and unnecessary at that point.
>
> Oh, and hiding the HTA title bar altogether is not an option as i need the
> minimize button as well as the application name in the window title bar.
>
> Any ideas ?
>
> Tom

It would appear that the best that can be done is use the
window.event.returnValue property to issue your message.

Function HandleUnload()
If bInProgress Then 'global flag true until processing is done
window.event.returnValue "Processing is in progress. " _
& "Don't try to close the window until done. "
End If

End Function

If the user 'cancels' the navigation, then the process is resumed.

I tried using the Sendkeys to release the dialog by pressing the
Cancel button, but the dialog box seems to be setup as system modal.
The setTimeout I set would not trigger the subroutine needed to clear
the dialog. I suppose you could launch a script in a separate thread
using Wscript.Shell Run, but that seems hardly worth it.
_____________________
Tom Lavedas