Re: executing a JS function when a browser closes

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

 Date:  Wed, 12 Apr 2000 11:06:03 +0100
 To:  "Michael Caton" <mcaton(at)mail.mc.maricopa.edu>,
"Rajnish Bhaskar" <9705228b(at)student.gla.ac.uk>,
<hwg-basics(at)hwg.org>
 References:  localhost maricopa
  todo: View Thread, Original
Hi,

Actually the onload function can be used to call in a standard js function.
Without the need for submitting a form. Also a specific form can be
submitted through the document.FORMNAME or document.forms[x] where x is the
number of the form (0 based indexing I think). You can use the syntax
onUnload="myfunction()" in the body.

According to my book on J/S the onunload function can also live in a
Frameset tag, but I've never got it to work. So it might be a good idea to
avoid it.

Of course if people are logging in to a site then you require them to log
out, it might be a good idea to place some form of checking on whether or
not they have accessed an internal link to prevent the onUnload triggering
at will, namely whenever the document changes...which could be a lot.

hth

David Rapp


> Try this:
>
> <body bgcolor="#FFFFFF" onUnload="Function(document.name)">
>
> where Function is function name and (document.name) should reflect the
form
> name (e.g. document.form1)
>
> I am not sure if this will work if you have more than one form on a
> page...hmm let me know it this works..

> > 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?

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