location.replace() in the onUnload event?

A

Andoni

Hi,

I am only writing for IE 5.5+ so no need for compatibility at all ;-)

I am trying to get my users to logoff which they finish on a particular
page. This is no problem (or should be no problem) as I can just put a
location.replace('http://www.mysite.com/html/logoff.jsp'); into the onUnload
event of the page they always finish on. This should fire when they click
the X in the corner (my app. is in a popup window) instead of hitting exit.

Unfortunately this won't work for me as it won't go to the page from the
onUnload= event unless I put an alert box in the method called like this:
(Example 1 does not work):

function endSession()
{
if(!submitting)
{
// end session.
location.replace('http://www.mysite.com/jsp/logoff.jsp');
}
return false;
}


function endSession()
{
if(!submitting)
{
// end session.
location.replace('http://www.mysite.com/jsp/logoff.jsp');
alert('in endSession()');
}
return false;
}

Can anyone shed any light on why the second one works? What can I use
instead of an alert box?

Thanks in advance,

Andoni.
 
M

Martin Honnen

Andoni said:
Hi,

I am only writing for IE 5.5+ so no need for compatibility at all ;-)

I am trying to get my users to logoff which they finish on a particular
page. This is no problem (or should be no problem) as I can just put a
location.replace('http://www.mysite.com/html/logoff.jsp'); into the onUnload
event of the page they always finish on. This should fire when they click
the X in the corner (my app. is in a popup window) instead of hitting exit.

Unfortunately this won't work for me as it won't go to the page from the
onUnload= event unless I put an alert box in the method called like this:
(Example 1 does not work):

function endSession()
{
if(!submitting)
{
// end session.
location.replace('http://www.mysite.com/jsp/logoff.jsp');
}
return false;
}


function endSession()
{
if(!submitting)
{
// end session.
location.replace('http://www.mysite.com/jsp/logoff.jsp');
alert('in endSession()');
}
return false;
}

Can anyone shed any light on why the second one works? What can I use
instead of an alert box?

You can open a logoff window with
<body onunload="window.open('logon.jsp');">
then logon.jsp can call
<body onload="window.close();">
if you so desire.
 
A

Andoni

Thanks for this, I was just reading the M$ site when I noticed that my
location.replace was itself also calling the onUnload event! You are right,
this way works well, thanks.

Andoni.
 
R

Richard Cornford

Andoni said:
Thanks for this, I was just reading the M$ site when I
noticed that my location.replace was itself also calling
the onUnload event! You are right, this way works well,
thanks.

If you are writing exclusively for IE 5.5+ you might be better off using
the onbeforeunload event.

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top