...

View Full Version : window.onbeforeload executes twice???



nikko50
10-12-2011, 04:00 PM
I want to use the below code to warn users that they are leaving the web form and to confirm they have saved their work. When I try the below and click the google link to leave the page I have to click through the dialog box twice. Why is that and how can I just get it the appear only once? I see if the user attempts to close the window the script works great but if the user attempts to click a link on the page they have to click through the dialoog box twwice. Please help.




<script type="text/javascript">


function goodbye(e) {
if(!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = 'Have you saved your work? You sure you want to leave?'; //This is displayed on the dialog

//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
}


window.onbeforeunload=goodbye;

</script>

<a href="www.google.com">google</a>

venegal
10-12-2011, 05:24 PM
Can you show a live example? In the code you posted, I don't see that dialog box you are talking about at all.

DaveyErwin
10-12-2011, 05:40 PM
Can you show a live example? In the code you posted, I don't see that dialog box you are talking about at all.

Right . A live example shows me the expected
results of that code while opening the
page from my file system gives me the result
described in O.P.

nikko50
10-12-2011, 09:14 PM
I only need this to function in ie. Can anyone help? Tracy

Kor
10-13-2011, 10:38 AM
For me, this one executes only once:


window.onbeforeunload = function(e){
var message = 'Have you saved your work? You sure you want to leave?';
e=e||window.event;
e.returnValue = message;
return message;
}

konoozi
10-13-2011, 11:56 AM
Which browsers are you testing in (include which versions)? Does the double activation happen in all of them?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum