This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do i trap the event of a browser window getting closed ?

 
Rasmeet Devji
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys!!
I need to know if it were possible to trap the event of a browser window getting closed, in java.
The reason why i want to do is this :
I've a chat application where in i have a logout button.
Now if the user clicks the logout button, i update his record back in the database and sign him off.
So far so good......
But the problem is, what if the user closes the browser window directly, i.e. without clicking on the logout button.
In any case i need to update his record, but how do i do this ???
Anyone to help me out ???
Thanks all !!
 
ray bond
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you must be using applets in your chat application ,
you can make java script to commuicate with your applet , use
document.applet["appletname"].appletmethods , kind of stuff to execute method of the applet , and then in html body tag use
onunload event so it will notify javascript about unload and javascript will notify applet about it ,
hope this helps.
 
Rasmeet Devji
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ray,
Thanks for the reply, but i'm afraid it did'nt help me much.
May be i'll explain it clearly. I have a servlet which embeds the html part (user interface).
When i tried calling the method of the applet, it didn't work out well
here's the sample code :
out.println("<html>");
out.println("<head><title>Mindteck Chat</title></head>");
out.println("<script language = 'javascript'>");
out.println("function logout()");
out.println("{");
out.println("var msg = \"leaves the room\" ");
out.println("document.chatapplet.broadcastMessage(msg)");
out.println("}");
out.println("</script>");
out.println("<body background=\"http://rasmeet:8080/gray.jpg\" onUnload = \"logout()\">");
out.println("<applet name = chatapplet code = "+ applet1 +
" codebase=/ " + "width = 600 height = 300>");
if(client != null)
{
out.println("<PARAM NAME = client VALUE=\" " + client + "\">");
}
out.println("</applet>");
out.println("</body>");
out.println("</html>");
what could be the reason ?
Thanx again !!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic