View Full Version : Using VBscript or Javascript to check if user closes window or navigates to diff page

06-11-2003, 07:53 PM
I'm working with asp on my site http://www23.brinkster.com/all4christ and I want to be able to display how many users are browsing the site at anytime.

I was able to achieve part of this goal using MS Access database..so when someone browses to my site their IP gets recorded and the page displays that their is someone browsing the site....the problem is when the person leaves the site or closes the browser the IP address is not deleted from the table so in essence the page still says the person is still browsing after they've left.

I have a feeling this could be done using code in a Global.asa file but brinkster.com doesn't allow the Global.asa for free accounts..Is there another way I can get around this like using javascript or vbscipt to check when the user closes the window or navigates to another site so I can delete the IP's


06-11-2003, 08:32 PM
Hi there,

As far as I know there is no way to use Javascript or anything else to detect when the window closes.

A lot of systems use the following method:

1) When someone comes to your site put their details in your database.
2) On each page they visit check to see if they have already been put in the database (by checking IP or assigned session variable).
3) If they are already in there then update a column called 'LastAccess' or something similar with the current time.
4) If they aren't in there, add them.
5) At the same place that you have this code, delete all records from your database where the 'LastAccess' column has a time that is less than the current time - 5 minutes. This will remove any user that has not accessed a page within the last 5 minutes (or whatever time you choose).
6) Then you can count the records in the table and display how many people are on your site.

As far as I know this is a pretty common way of doing it, although I think you are right, you can also do it with the global.asa.

Hope this gives you some ideas.

06-13-2003, 11:19 AM
thanks Galdo...this will do. The Global.asa would have worked better but this is still alright. I'll use this...thanks for your help!!