Click to See Complete Forum and Search --> : Is there any way to stop window closing with onunload?


jovialjonny
09-15-2003, 12:55 PM
Hi,
I am looking to do a "Are you sure you want to leave the page" message as part of a web-based applciation using onUnload and confirm().
I cannot figure out how to make it such that when the user clicks 'Cancel' they does not leave the page.

Any ideas on how to do this?

Jona
09-15-2003, 01:29 PM
<body onunload="if(confirm('Are you sure you want to exit?')){return true;}else{return false;}">


[J]ona

AdamGundry
09-15-2003, 02:07 PM
Jona, your code does not work on IE 6 or Mozilla 1.4. AFAIK, there is no reliable way you can do this, as it is a browser security issue. You may be able to put a window.open() call in the onunload handler to reopen the window.

Adam

Jona
09-15-2003, 02:15 PM
Originally posted by AdamGundry
Jona, your code does not work on IE 6 or Mozilla 1.4. AFAIK, there is no reliable way you can do this, as it is a browser security issue. You may be able to put a window.open() call in the onunload handler to reopen the window.

I don't know why I even "answered" the question... I don't particularly enjoy dealing with this sort of thing... I'll remember not to respond to these kinds of posts anymore. :p

[J]ona

AdamGundry
09-15-2003, 02:18 PM
If we can get WebDevFaqs (http://www.webdevfaqs.com/) up and running, we should just be able to answer simple questions by posting links. :)

Adam

Jona
09-15-2003, 02:20 PM
Originally posted by AdamGundry
If we can get WebDevFaqs (http://www.webdevfaqs.com/) up and running, we should just be able to answer simple questions by posting links. :)

w00t! lol...

[J]ona

blacib
02-01-2004, 03:03 PM
Originally posted by AdamGundry
You may be able to put a window.open() call in the onunload handler to reopen the window.

Adam

The opening of a new window does it work also with GoogleBar?

Jona
02-01-2004, 03:36 PM
Originally posted by blacib
The opening of a new window does it work also with GoogleBar?

Not if the GoogleBar is a good popup blocker...

[J]ona