wood burning stoves 2.0
The moose likes HTML, CSS and JavaScript and the fly likes window onunload Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "window onunload" Watch "window onunload" New topic

window onunload

samart mateo
Ranch Hand

Joined: Feb 06, 2006
Posts: 37
Is there any properties that i could use that could treat window the same way we treat a page body?

I would like to call a function that could clear up the logs data in the database when a window is closed or terminated inappropriately.

the problem is that when a page is closed without logging out a certain user, the user log data still treats him as online and he wouldnt be able to log in again. PS: i didn't use jsp session for this as the system needs to save a user log history.

eg: is there exist a 'window onunload' function that could works like 'body onunload' method?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63837

Moved to the HTML/Javascript forum.

[Asking smart questions] [About Bear] [Books by Bear]
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
There is an onunload and onbeforeunload, but it is not reliable and is fired by links, refresh, and exiting/closing so it is not easy to do.

You really need to figure out a way to clean it up on the server.

samart mateo
Ranch Hand

Joined: Feb 06, 2006
Posts: 37
TQ eric.

However, for those who couldnt understen my earlier problem statement, here's some more explaination to go with.

For security, the system wouldnt allow the same user to log on at the same time. For this, I had the system to store the user's status in the DB.

However, the problem arise when the user exits the program by clicking the browser's close button or may be the computer suddenly shuts down. The system still had the user's status as logged in. And when the same user would want to log back in, the system would deny his entry.

I think the banking system would have the same security issue as mine. If anybody had experience the same problem, please help me. Thank you.
Niki Nono
Ranch Hand

Joined: Mar 20, 2005
Posts: 256
maybe you can create a link between your client and your server where the server expects to be informed every few minutes.
If no response arrives for such time then automatically assume that the link has been broken and let the server logout the user.
The piece of code at the branch would be present in some web page.

Instead of embedding it in the main page, maybe write a seperate web page and create a 0/0 frame for it. This would not be visible and when the user closes the main window, this page's onunload would also get called where you would inform the server that the user is logging out.

and i think since it is in a seperate page it wont be affected by all the happenings in the main page.

hope the above is clear and please validate if above is correct.

Life called,so here I am.<br />Cheers<br />Niki.:-)
samart mateo
Ranch Hand

Joined: Feb 06, 2006
Posts: 37
Thanx for the idea. I'll try that out.
samart mateo
Ranch Hand

Joined: Feb 06, 2006
Posts: 37
Hi niki,

do you mean that i should have a main page that contains an iframe in which all the activities involved would be done in the iframe? so that the main page would not be changed at all regardless of any activities done with the system?

I cant implement this is the system is already about 90% complete and it's a time consuming work to change the concept.

dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
Generally you do not need any frames for this approach. just add a simple JS methods which polls a server using httpxml or something like that

Edit: banking systems, at least my, work differently, they just log off all previous at relogin attempt
[ February 07, 2006: Message edited by: dema rogatkin ]

Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
I agree. Here's the link: http://aspose.com/file-tools
subject: window onunload
It's not a secret anymore!