Re: executing a JS function when a browser closes

by "David Rapp" <david(at)rappd.freeserve.co.uk>

 Date:  Tue, 11 Apr 2000 23:06:00 +0100
 To:  "Rajnish Bhaskar" <9705228b(at)student.gla.ac.uk>,
<hwg-basics(at)mail.hwg.org>
 References:  localhost
  todo: View Thread, Original
Hi,

I think it's possible. If you use the unload function JavaScript can control
an event on the closure of the page. But you'd need some error checking to
prevent accidental logouts on leaving the current page.

Perhaps by setting a variable in the onclick function of internal links,
setting a variable then in the unload function checking the variable to see
if they should log out or not.

Of course thats more your problem ;-).

Anyway the onUnload function is an event handler that lives in the body of
the document or can be placed in the Frameset tag (Never got it to work
although the spec says it should).

Call it by placing something like this in your body or frameset (Note I
haven't had much luck with the Frameset tag so a BODY is a much better place
for it) tag - onUnload="myfunction()"

HTH

David Rapp

BTW It's late and I tend to babble, if this makes no sense just email and
I'll try to explain it better.

> Hi all,
> I was just wondering, is it possible to have a Javascript function
> executed just before a broswer closes?  What I have is a situation where
> people will be logging on to a site, and I want them to be logged out,
> even if they forget to press the logout button, ie when the close the
> browser.  Is this possible?
>
> Thanks,
> Raj.

HTML: hwg-basics mailing list archives, maintained by Webmasters @ IWA