Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1612
  • Last Modified:

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
0
YZlat
Asked:
YZlat
  • 2
  • 2
  • 2
1 Solution
 
omgangCommented:
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">
0
 
YZlatAuthor Commented:
What is cancelBubble and where is it declared?
0
 
YZlatAuthor Commented:
if you mean window.event.cancelBubble, it does not work, unfortunatelly
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
omgangCommented:
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">
0
 
RobSampsonCommented:
It doesn't look like this is possible:
http://support.microsoft.com/kb/946214

since it is a bug in IE.

It looks like about the best you can do is set
  sysmenu="no"

in the <HTA:APPLICATION tag, and then add your own button for closing that runs your form close:
Sub FormClose()
intAnswer = _
    Msgbox("Do you want to close this form?", vbYesNo, "Form Close")
If intAnswer = vbYes Then
    Msgbox "Thank you and goodbye"
    window.close
Else
    Msgbox "Cancelled form close"
End If
End Sub

Open in new window


The only thing this doesn't stop is people pressing ALT+F4

Regards,

Rob.
0
 
RobSampsonCommented:
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.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now