Confirm before closing page

ultraman

Centurion
Joined
Dec 31, 1969
Messages
138
Location
Quebec, Canada
Hi all !

Is there a way to catch the unload event when someone close the IE window with the "X" ? I tried JS in Body onunload but it's not working. I just want to ask a confirmation message before he close the window. If the answer is yes, just close the window, otherwise cancel the close event.

Is it possible ?
 
Maybe have a "close" button. Then if users click that, popup a msg if they want to close...

My JS looks like this:

Code:
<script language="javascript">
		 function confirm_delete()
{
  if (confirm("Are you sure you want to delete the Activity?")==true)
    return true;
  else
    return false;
}
		
		</script>

My button looks like this:

Code:
<asp:Button Runat="server" Font-Bold="True" BackColor="Red" ID="btnDelete" CommandName="Delete" Text="Delete Activity"></asp:Button>


Then in the code behind:

Code:
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim _myButton As Button = CType(e.Item.FindControl("btnDelete"), Button)
            Dim test = _myButton.Text
            _myButton.Attributes.Add("onclick", "return confirm_delete();")
        End If
 
Back
Top