473,326 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

need a solution when window is closed

Hi ,

In my project i need to maintain online users. But some one close the browser with out clicking the logout. So i face the problem to find who is in online currently. Plz tell me the way how to check that user is closed the window or not.

I wrote the code in onunload event. But that event is called when i click the refresh button or i moved any other location. So plz give the solution for me.

Thanks,
Raja Mohamed.S
Mar 10 '07 #1
3 1762
AricC
1,892 Expert 1GB
Hi ,

In my project i need to maintain online users. But some one close the browser with out clicking the logout. So i face the problem to find who is in online currently. Plz tell me the way how to check that user is closed the window or not.

I wrote the code in onunload event. But that event is called when i click the refresh button or i moved any other location. So plz give the solution for me.

Thanks,
Raja Mohamed.S
What do you have coded thus far?
Mar 11 '07 #2
Hi ,

In my project i need to maintain online users. But some one close the browser with out clicking the logout. So i face the problem to find who is in online currently. Plz tell me the way how to check that user is closed the window or not.

I wrote the code in onunload event. But that event is called when i click the refresh button or i moved any other location. So plz give the solution for me.

Thanks,
Raja Mohamed.S

Hi,
To find whether the user has closed the window without clicking logout, i included the following lines in my script. This would track the window close regardless of its status(Window close in maximised state or window close in minimised state)

<script language="JavaScript">
function initUnload()
{
var top=self.screenTop;
if (top>9000)
alert("window closed"+top);
else if(top<0)
alert("window closed"+top);
}
window.onunload = initUnload;
</script>

Thanks,
Santhu Balu
Mar 12 '07 #3
steven
143 100+
On a project I'm currently working on, I needed to record a users last access time when they left the website, either by logging out, closing the browser, or visiting another website. You want to use the onbeforeunload event. I had this run a javascript function to make a synchronous (ajax) call to a PHP script which did the work. Using the onbeforeunload event will do what you want.

My code, if it helps:

Expand|Select|Wrap|Line Numbers
  1.     // add event listener
  2.     function addListener(obj, event, func) {
  3.       var obj = (typeof obj == 'string' ? d.getElementById(obj) : obj);
  4.       if (obj && obj.addEventListener) {
  5.         obj.addEventListener(event, func, false);
  6.       } else if (obj && obj.attachEvent) {
  7.         obj.attachEvent('on'+event, func);
  8.       }
  9.     }
  10.  
  11.     // return AJAX object
  12.     function getHttpXml() {
  13.       if (window.XMLHttpRequest) {
  14.         return new XMLHttpRequest();
  15.       } else if (window.ActiveXObject) {
  16.         try {
  17.           return new ActiveXObject("Msxml2.XMLHTTP");
  18.         } catch (e) {
  19.           try {
  20.             return new ActiveXObject("Microsoft.XMLHTTP");
  21.           } catch (e2) { } // no Ajax support
  22.         }
  23.       } return null;
  24.     }
  25.  
  26.     addListener(window, 'beforeunload', bye);
  27.     var xmlHttp = getHttpXml();
  28.  
  29.     function bye() {
  30.       if (xmlHttp) {
  31.         var url = "script.php?action=leaving";
  32.         xmlHttp.open("GET", url, true);
  33.         xmlHttp.send(null);
  34.       }
  35.     }
  36.  
  37.  
  38.  
You can add this in the head of your html page, if you want, just edit the relevant line to change the filename / parameters you want to call. I hope that helps.
Mar 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Matt Kruse | last post by:
See: http://www.mattkruse.com/temp/window_closed.html It looks like the .closed property of a window is inaccessible if the window is actually closed. Other browsers have no problem detecting...
10
by: Tom Szabo | last post by:
Is there an event when that triggers when the window is closing.... I am talking about when the user clicks on the cross on the right top corner of the window!!!
4
by: Michael Gorbach | last post by:
Iv got a little bit of a threading problem. Iv got a form which handles events fired by an object running on another thread (the event handlers are executed on a thread differnet from the form's...
3
by: GreggTB | last post by:
I've been working on what appears to be a cursed ASP.NET project....so many things have gone wrong that Murphy would be proud. ;-) Anyway, I shut down the project in VS.NET at one point this...
7
by: Jaggu | last post by:
Hi , I need to close main window, once the child window succesfully opens else main window to remain. In my case when I close the main window immediately after the "window.open()" as mentioned...
21
by: alistair_henderson | last post by:
Morning All, I have some code for a website which uses 'window.open' to simulate modal dialog boxes. I use the window.closed property to decide if the window object exists at various points. ...
10
by: morangolds | last post by:
Hi, I've been having a problem with C++ Windows Forms apps not "ending" when you close the form window. I've searched about this problem all over the place and most searches have lead me to...
12
by: Phil | last post by:
I can check for MdiChildren.Length=0, but which event handler should I put this in to detect when a child window is closed? TIA Phil.
6
by: SAL | last post by:
Hi, VS2005 post I'm opening a window using the following syntax: Protected Sub lbEstValue_Click(ByVal sender As Object, ByVal e As System.EventArgs)...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.