• 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 to capture close[X] function in javascript?

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

Main Page


newWindow.jsp

reply
    Bookmark Topic Watch Topic
  • New Topic