s_lavie
asked on
Detect before/when the browser leaving to another webpage
When a JApplet is loaded and the browser browse to another webpage the applet (the main JFrame) is closed without a warning. Can a I detect that it in advance to prevent the browser from leaving the webpage or at least warn the user or so?
ie:
<body onLoad="alert( 'Hi!' )" onUnload="alert( 'Bye!' )">
<body onLoad="alert( 'Hi!' )" onUnload="alert( 'Bye!' )">
ASKER
Can I issue a yes/no dialog that the user can regret before the browser leaves the webpage?
There is
onBeforeUnload
but it is only available in Internet Explorer
http://www.webreference.com/dhtml/diner/beforeunload/index.html
----------------
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
function unloadMess(){
mess = Leaving so soon?"
return mess;
}
function setBunload(on){
window.onbeforeunload = (on) ? unloadMess : null;
}
setBunload(true);
//-->
</SCRIPT>
onBeforeUnload
but it is only available in Internet Explorer
http://www.webreference.com/dhtml/diner/beforeunload/index.html
----------------
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
function unloadMess(){
mess = Leaving so soon?"
return mess;
}
function setBunload(on){
window.onbeforeunload = (on) ? unloadMess : null;
}
setBunload(true);
//-->
</SCRIPT>
ASKER
I'm quite weak with JavaScript. I'd appreciate if you add a sample code that includes the yes/no dialog and the canceling of moving to another webpage,
10x
10x
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Mmmmm.....pink ;-)
That will fire javascript when the page is loaded, and when they leave the page...
You can't stop them leving though, so what you want to do isn't possible :-(