Checking if user is offline/online

80 views
Skip to first unread message

António Ramos

unread,
Dec 2, 2016, 1:11:08 PM12/2/16
to web...@googlegroups.com
What could be the best way to check if a user is disconnects?

I was thinking of  this

     <script type="text/javascript">
       $(document).ready(function()
{
    $(window).bind("beforeunload", function() { 
        call a controller function to set the user as offline
    });
});
     </script>

but this is not perfect because when the user moves to another URL inside the same app this event keeps getting triggered on url change.
Any better ideas?


Regards
António

Massimo Di Pierro

unread,
Dec 2, 2016, 5:21:30 PM12/2/16
to web2py-users
You need a websocket server like web2py/gluon/contrib/websocket_messaging.py Examples are i the file itself.

Marlysson Silva

unread,
Dec 3, 2016, 2:25:50 PM12/3/16
to web2py-users

Anthony

unread,
Dec 3, 2016, 3:36:10 PM12/3/16
to web2py-users
On Saturday, December 3, 2016 at 2:25:50 PM UTC-5, Marlysson Silva wrote:

Looks like that is for tracking whether the browser itself is online vs. offline, not whether the user has simply navigated away from your app or closed the tab.

Anthony

Marlysson Silva

unread,
Dec 4, 2016, 11:43:40 AM12/4/16
to web2py-users
Then isn't online/offline it verify whether user get out focus on current page..

Anthony

unread,
Dec 4, 2016, 3:48:11 PM12/4/16
to web2py-users
On Sunday, December 4, 2016 at 11:43:40 AM UTC-5, Marlysson Silva wrote:
Then isn't online/offline it verify whether user get out focus on current page..

In that context, "offline" means that the browser no longer has an internet connection.
 
Reply all
Reply to author
Forward
0 new messages