views:

64

answers:

3

Want to display a "confirm" message in my asp.net appl, when the window closes, but when the Cancel button is pressed, the page closes, the event is not Canceled. I tried a different approach: I use; event.returnValue = "Message"; This approach works (when cancel is pressed, page does not close), but I get the "Message" that I specify plus some other message; "Click Acept or Cancel to calcel" or something similar.

How can I create a message on the client side that only displays the text that I specify

Many thanks in advanced guys!!!

A: 

You can't. The confirm message shown when a script attempts to prevent browser close/leaving the page is in part defined by the browser. You can only define part of the message.

Jonathan Fingland
A: 

This can't be done as a confirm message is shown when script attempts to change the closing behavior of the page by the browser

Meetu Choudhary
what if I use:event.returnValue = "Message"; Is there a way to define the message?Cheers
I don't think so onbeforeunload event will give that confirm box. you can try onload event probably that wont give you this confirm box
Meetu Choudhary
A: 
window.onbeforeunload = function() {
  if(!confirm("Well?"))
    return "PLEASE STICK AROUND!";
}

Note: onbeforeunload fires when the document is unloaded, not the window. So every redirect will fire the event. I'm afraid this is the best you can do.

Josh Stodola