• Post Reply Bookmark Topic Watch Topic
  • New Topic

Closing the browser  RSS feed

 
Reeti Saha
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:
I'm using jsp for my web based project. I've written code for some clean up operation when a button is pressed..but I want the same method to be executed if a user closes the browser window also.
Pls. let me know how to proceed.
Regards
Reeti
 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Far as I kow, you will have to use javascript.
The window.close() method
http://www.michael-thomas.com/javascript/ex_window_openclose.htm
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But realize that you're not GUARANTEED that this method will be run whenever someone closes your browser window... what if they simply type a new URL into their browser? What if the browser doesn't support Javascript, or they've turned it off?
Make sure your session.setMaxMaxInactiveInterval(int) is set to an appropriate period so that its long enough so it doesn't kill people's sessions who are just slow while surfing around your site, and its short enough to invalidate people's sessions who have left your site without logging out.
------------------
- Jessica Bradley
HP Bluestone
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the most common ways *I* close my browser is by abnormally terminating the program (yes, you can tell I use Netscape - still waiting for Microsoft to do a native port of IE for Linux ).
Try catching *THAT*
[This message has been edited by Tim Holloway (edited December 18, 2001).]
 
Jason Kilgrow
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Reeti Saha:
Hi:
I'm using jsp for my web based project. I've written code for some clean up operation when a button is pressed..but I want the same method to be executed if a user closes the browser window also.
Pls. let me know how to proceed.
Regards
Reeti

It depends on the browser you are using.
close is an event just like leftClick or rightClick. You'll have to code the close event for each browser you want it to work on. Once you have identified how to capture the event, it's just a matter of having the javascript function take the browser to the page that does the clean up before it closes.
I expect it will be a bit tricky but it should be possible.
 
shikhar singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Reeti,
You can try this method.
On the unload event of the window (this will happen when the user closes to window), call a javascript function which opens a new window and loads a JSP which does all the cleanup. This window can be automatically closed, once the required task is done.
This seems to be unconventional approach but will definitely address your problem.
This won't solve the problem like if somebody switches off the computer or network go hay-wire..
Hope this helps
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I've read the recommendations and I'd have to say: Can't really be done, definitely not reliably. If you try to use use any of the solutions and trust them, the only thing you can guarantee is that one day when you aren't expecting it, they will let you down.
Dave
(if you open a second separate window and wait for a response in the second that window but the user closes the second window then you have to open a third window to handle the second one closing prematurely etc etc)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!