Link to home
Start Free TrialLog in
Avatar of YZlat
YZlatFlag for United States of America

asked on

How to cancel hta form close

I have the following code activated when the user clicks the close button:

Function FormClose()
intAnswer = _
    Msgbox("Do you want to close this form?", vbYesNo, "Form Close")

If intAnswer = vbYes Then
    Msgbox "Closing the form..."
Else
    Msgbox "Cancelled form close"
End If

How can i cancel form closing if the user clicks "No"

End Function
Avatar of omgang
omgang
Flag of United States of America image

Try this.  I haven't actually used it myself.  Let me know.
OM Gang

<script language=vbs>
Sub MyCloseFunction
    Dim intAnswer, msg
    msg="Do you want to close this form?"
    intAnswer=MsgBox(msg, vbYesNo, "Form Close")
    If inAnswer=vbYes Then
        MsgBox "Closing the form..."
    Else
        cancelBubble=True
        MsgBox "Cancelled form close"
    End If
</script>
<body onbeforeunload="MyCloseFunction">
Avatar of YZlat

ASKER

What is cancelBubble and where is it declared?
Avatar of YZlat

ASKER

if you mean window.event.cancelBubble, it does not work, unfortunatelly
Yeah, I've also tried the same with javascript and the message boxes do display but the browser window closes regardless of which button is clicked.

I'll keep looking but I'm at a loss right now.
OM Gang


<script language="javascript">
function promptonclose()
{
      if (confirm('Do you want to close this form?')){
            alert('you clicked OK');
      }else{
            alert('Cancelled form close');
            window.event.cancel.Bubble = true;
            window.event.stopPropogation();
      }
}


</script>
 

</head>

<body onbeforeunload="promptonclose">
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Not sure if that posted...took about half an hour ;-)

BTW, the sysmenu="no" removes the max min close buttons from the top right of the window.

Rob.