Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Overriding onBeforeUnload dialog message
Old 02-09-2006, 09:36 PM Overriding onBeforeUnload dialog message
Junior Talker

Posts: 2
Trades: 0
Hi there,

Does anyone know how to suppress the default messages?

1. "Are you sure you want to navigate away from this page?"
2. "Press OK to continue, or Cancel to stay on current page"

I need to provide the user a custome message. I tried many approachs, but non of them seem to work. I tried to use a confirm box instead, but for some reason, the return value for onBeforeUnload event seem to be used as string, so return false to the event CANNOT stop the page from refreshing.

Thanks,
Welles
welles is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-10-2006, 05:45 AM Re: Overriding onBeforeUnload dialog message
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,520
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
redefine the function to do what you want by writing your own function called onBeforeUnload()
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-10-2006, 02:15 PM Re: Overriding onBeforeUnload dialog message
Junior Talker

Posts: 2
Trades: 0
Thanks for your reply, I already defined a new function for the event but it still doesn't work.

Code:
<script language="javascript">
window.onbeforeunload = onBeforeUnload_Handler;
 
function onBeforeUnload_Handler(){
fConfirm('param1','param2','param3','param3');
}
 
function fConfirm(p1,p2,p3,p4)
{
//do something with p1, p2, p3, p4....
 
//this shows the default dialog box 
//event.returnValue = 'Any changes will be lost if you proceed.';
 
//this shows the custom confirm box, but it doesn't stop the page from 
//refreshing even the user click the "Cancel" button
if(!confirm("Any changes will be lost if you proceed.")){
return false;
}
return true;
}
}
</script>

Last edited by welles; 02-10-2006 at 02:16 PM..
welles is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Overriding onBeforeUnload dialog message
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11903 seconds with 12 queries