Click to See Complete Forum and Search --> : Problems executing onUnload...


pbsthlm
04-15-2004, 03:45 AM
Hi there,

I'm trying to execute an onUnload when closing my browser. I have managed to get it to work except for when i click on an empty area in the browser window. For some reason this disables the onUnload. I'm capturing the clicks and it works for clicking a link but not if you click on "nothing".

This is the code;

<SCRIPT LANGUAGE="JavaScript">
<!--

var surfa=false;
var PopUrl='www.microsoft.com';

function Klicka(){
surfa=true;
}

function Oppna(){
if (surfa==false){
open(PopUrl,'','');
}
}
if (!document.all){
window.captureEvents(CLICK);
window.onunload=Oppna;
window.onclick=Klicka;
}
else {
document.onclick = Klicka;
window.onunload=Oppna;

}
//-->
</SCRIPT>

Is it possible to execute the onUnload even after having clicked an empty area in the browser?

JayDie
04-15-2004, 03:58 AM
Originally posted by pbsthlm
trying to execute an onUnload when closing my browser

I thought the 'onUnload' event only fires when you change (unload) the page in your browser, not when you close the browser? :confused:

Originally posted by pbsthlm
trying to execute an onUnload when closing my browser
I have managed to get it to work except for when i click on an empty area in the browser window.

Don't get the point... you want to unload (change) the page if you click on a 'empty :confused: area of your page? Use the onclick event??

JayDie

pbsthlm
04-15-2004, 04:11 AM
Well, the problem is this...

I only want the unLoad to fire when I close or refresh the browser... If i only use the onUnload straight up, the popup will display everytime I click a link (thus the page changes). So I have to disable the onUnload when I click any links... it works that way right now, thus i can click a link without the onUnload firing and when I actually close the browser it fires. But when clicking somewhere else the onUnload somehow gets disabled and thus does not fire when i close the browser. Try the script out and you will see what i mean.

Click the link and close the browser = the onUnload fires.

Click somewhere else and close the browser = the unLoad does not fire.

Thanks