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 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2011
    Posts
    59
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Exclamation Log Out of system when close browser window

    Hi folks,

    I've got a chat program which relies on a column in a MySQL database to see if he/she has logged out or not. But if you close the browser window, the computer still thinks you're online. I wrote this in the JavaScript section cos I think it would definitely need Javascript. So any help for updating the database in any way? Thanks!!

    Lucas

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Use a session cookie for that.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Jun 2011
    Posts
    59
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks,

    but the main problem is that using the computer you can't find if a person if offline or online because session variables are only in the computer, not accessible by another person's computer. That's why i made a loggedin column in my database, cos databases are accessible everywhere.

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    You can add/attach an event listener for "onbeforeunload" to the window object and do whatever you want to do in the callback. You can even give a string as a return value. This string will be displayed to the user together with two buttons. That will give the user the choice to stay on the page or to leave it (no other options possible).

    Code:
    window.onbeforeunload = myExitFunction;
    
    function myExitFunction() {
       // your actions here
       ...
       return "This string will be shown in a message box";
    }

  • #5
    New Coder
    Join Date
    Jun 2011
    Posts
    59
    Thanks
    3
    Thanked 0 Times in 0 Posts
    can jQuery ajax be performed in the window.onbeforeunload event as well?

  • #6
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Just try ...


  •  

    Posting Permissions

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