Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Ajax & onUnload

  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    28
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Ajax & onUnload

    I am trying to create a system that keeps track of which members are online and which are not. The issue I am running into is that I need a method to set the member's status to offline when they close the browser window. It will currently set a members status to offline if they go to a different page, but not if they close the window. The current function is set as the onUnload event of the body:

    Code:
    function onUnloadRequest()
    {
    	xmlhttp = null;
    
    	if(window.XMLHttpRequest)
    	{
    	  xmlhttp = new XMLHttpRequest();
    	}
    
    	else if(window.ActiveXObject)
    	{
    	  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    	}
    	if(xmlhttp != null)
    	{
    	  xmlhttp.open("GET", "ajx_change_status.php", true);
    	  xmlhttp.send(null);
    	  return xmlhttp.responseText;
    	}
    	else
    	{
    	  alert("Your browser does not support XMLHTTP.");
    	}
    }

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by bengaltgrs View Post
    The issue I am running into is that I need a method to set the member's status to offline when they close the browser window. It will currently set a members status to offline if they go to a different page, but not if they close the window.
    if u want to find out if a browser window has been closed...u can't
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Server really needs to do this with a session timeout unless you are polling the server, you can see when the polling stops.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #4
    New Coder
    Join Date
    Oct 2007
    Posts
    28
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Do you know of any websites tutorials on either of these topics? I've been googling for a while with no real results.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •