• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !!
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic