Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handle window close event

 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to call a servlet when a window is closed.I used onunload(),but that is triggered even at the times when i refresh the page or click a link on the page.
But, i want that my function should be triggered only when i close the window.
Can anyone tell me how can i do that.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no way to detect this.

What is it that you feel that you need to do on window close?
 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, we have some files on server side that needs to be deleted when the client closes the browser.When client is refreshing the window or if he is clicking the link, it means he still wants to view the window.So, in that case we can not delete the files.We have to delete the files, only when we are sure user is done with viewing our window and now he is closing the window.

Please tell me the solution if the situation is clear to you.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll have to rely on the session timeout.
 
ShaikSalam Bashoeb
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raj, there is one nice solution for your problem is

use onunload event in body tag and i hope your calling one javascript method. in that method you can check your window got closed or not by using


I hope you got the solution.................
[ December 14, 2008: Message edited by: ShaikSalam Bashoeb ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ShaikSalam Bashoeb:
use onunload event in body tag

That event is fired for all cases where the page is unloaded, including navigation. It makes no distinction on why the page is being unloaded.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides, the onunload (and onbeforeunload) events aren't specified in W3 HTML specification. Although the major webbrowsers supports them, you shouldn't rely that the webbrowser used by the client supports it. For example Opera, which usually follows the W3 specs extremely strictly, doesn't support it.

As Bear said, do it when the session times out. You can use HttpSessionListener or maybe HttpSessionBindingListener for this.
 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestions
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic