Click to See Complete Forum and Search --> : Why doesn't it work???


zeccaman
04-12-2006, 09:29 AM
Hi, I have a simple script which execute simple code when a user close the webpage he is visiting. This is the code.

<SCRIPT FOR=window EVENT=onunload>
if(getSet()==false) location.href="logout.jsp";

</SCRIPT>

<SCRIPT>
boolean settings= false;
function set() {
settings=true;
}

function getSet() {
return settings;
}
</SCRIPT>

I put the variable setting otherwise because it always executes the code.
so, when I click the link I want it is <A HREF="page.jsp" onClick="set();"> Menu </A>

now it doesn't understand when the user closes the window! I think it is a scope variable problem.

Thank you

phpnovice
04-12-2006, 09:56 AM
Try changing this:

<SCRIPT FOR=window EVENT=onunload>

to this:

<SCRIPT FOR=window EVENT=onbeforeunload>

stephen1davis
04-12-2006, 10:07 AM
i thought that "onbeforeunload" was not standard or something...

zeccaman
04-12-2006, 10:25 AM
"onbeforeunload" does not work too :(

Do you think that it is a problem if I have 2 events at the same time as in this case?

phpnovice
04-12-2006, 02:22 PM
You only showed one. Also, I've never used this nomenclature before:

<SCRIPT FOR=window EVENT=onbeforeunload>

Under usual circumstances, I'd say, yes, that is the problem -- just as you can't code the same event twice inline and you can't do the following in script twice:

window.onbeforeunload = function