aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How to capture close[X] function in javascript? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to capture close[X] function in javascript?" Watch "How to capture close[X] function in javascript?" New topic
Author

How to capture close[X] function in javascript?

Prathyusha Reddy
Ranch Hand

Joined: Jan 20, 2010
Posts: 31
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jul 29, 2010
Posts: 9
Well i think that you should do an ajax request to update that user status with setInterval .


Web Programmer
http://rafaelmd.com.br
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jul 29, 2010
Posts: 9
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

Joined: May 02, 2010
Posts: 105

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

Main Page


newWindow.jsp


Wake up! Don't let your smile be snatched away by anybody!
Regards, Eswar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to capture close[X] function in javascript?
 
Similar Threads
capture window closing
Closing browser clicking on close button.
Suggestion - Block an item to an user (e.g. onunload, lock of table) show the message "Item in use"
Logout when exit
calling a javascript function on closing browser