This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to capture close[X] function in javascript?

 
Prathyusha Reddy
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All...
i have a problem with closing up the IE window close button....
i am trying to run some script/command (updating some user status in database) when the user tried to close the windows close[x] button....

i have search for the internet and found out there is "onUnload" method which can be put on the HTML body tag. but i have found that this method has some weaknesses,such as when the page is refresing or when the user press F5, this unload event will also be called....(in other word, i only want the onUnload even is called when the user try to log off or close the windows by clicking the windows button)..

so i wonder whether there is any script/method can reliably capture the windows close[x] button to run certain code/commands before the windows is closing....
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you search the forum, you will see that this has been asked 100's of times and there is no reliable way to determine what causes the page to unload.

Eric
 
Rafael Monteiro Dourado
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i think that you should do an ajax request to update that user status with setInterval .

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rafael Monteiro Dourado wrote:Well i think that you should do an ajax request to update that user status with setInterval .



And you want to take down the users server as it gets hammered with requests?

Eric
 
Rafael Monteiro Dourado
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imagine a table "user" with the columns :

id | name | last_request

And with the setInterval function you update the last_resquest every minute. When the last_request of an user is smaller than current time plus one minute, that user is off .

 
Eswar Nec
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here i give the code for, Ideentify the close event in FrieFox and IE.

Main Page


newWindow.jsp

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic