Click to See Complete Forum and Search --> : Check if user leaves the page


bigbenjam
11-18-2003, 05:53 PM
Hello everyone!

My problem is that i need to prevent the user from unwillingly leaving my site(if he/she clicked a link in outlook f.e.) So my site should detect if the user changes the url and if it has another domain(so url changes inside the site should be unnoticed) then a popup should appear which warns the user of leaving the site.

Has anyone a idea how to hadle that with nice little scipt? :)

thanks in advance!!

steelersfan88
11-18-2003, 06:37 PM
Not quite sure i understand...

bigbenjam
11-19-2003, 03:21 PM
Thanks for the help, but thats no helping me much, because my page is a webapp, so the window should prevent to be closed or replaced with another url at any costs.
And I had found a way perhabs, but it is not working right now:

<SCRIPT language=JavaScript>
function onUrlchange ()
{

alert(window.location.href);
window.event.returnValue= "You are about to navigate away"
window.event.cancelBubble=true;

}
</SCRIPT>
</HEAD>
<BODY onbeforeunload="onUrlchange();"/>

the problem is that if i enter "www.msn.de" f.e. into the
addressbar of the ie, the script shows up and i can cancel the
relocation, but the alert(window.location.href); does not give
me the "www.msn.de" but the url of this test html file!

If I could somehow get this new entered address, i could
compare the url with my internal sites, and if it differs, i would display the warning