Thanks again Isaac!
Here is my final code so people can enjoy (add the script tags around the
javascript). It does not fire when submit is clicked, but if you refresh or
use the back/forward button or try to close the browser it fires.
function unloadMessage(){
message = "Dont go.. what you typed in the form will be lost!"
return message;
}
function setBeforeUnload(on){
window.onbeforeunload = (on) ? unloadMessage : null;
}
setBeforeUnload(true);
<form>
<input type="text">
<input type="submit" onClick="setBeforeUnload(false);">
</form>
-----Original Message-----
From: s. isaac dealey [mailto:[EMAIL PROTECTED]
Sent: Friday, February 01, 2008 3:49 PM
To: CF-Talk
Subject: Re: OT: javascript to keep a user from navigating away
> I would like to make javascript that when the window.onUnload is
> fired to pop up a confirm() saying "hey if you leave now your form
> information will not be saved. Do you wish to continue?". But I think
> once onUnload fires there is no stopping the user from leaving the
> page. Can you cancel onUnload once it fires?
I believe it's doable... not necessarily the best case for usability...
however...
in order to work across both IE and firefox/moz you have to use two
event handlers. In moz, "onunload" can be cancelled
<body onunload="return confirm('Lose your work?');">
in IE, the onunload event doesn't fire until after the browser is
already closed, however, they have a prioprietary onbeforeunload event,
so you can use that one instead to do the same thing for IE. Iirc you
don't have to do any special checking or anything, just copy whatever
you put in onunload into onbeforeunload also and you'll get the result
you want.
I was asked to do this several years ago for a company in Ft Lauderdale.
hth,
ike
--
s. isaac dealey ^ new epoch
isn't it time for a change?
ph: 503.236.3691
http://onTap.riaforge.org/blog
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:297966
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4