White Wizzard
2007-Sep-20 14:58 UTC
Executing code when the user hits the X button on the browser
I am writting an app that is going to record login times, logout times and the session data of a user of the system. This will work if the user manually logs out, but I would like it to record when the user quits if the users exits the browser (or goes to a page not in our application). Any ideas on how to accomplish this task? Any help is appreciated. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jonathan Rochkind
2007-Sep-20 16:48 UTC
Re: Executing code when the user hits the X button on the br
Well, there''s no good way to do that easily or perfectly. But here are some ideas. You could try to do fancy javascript to ''catch'' the closing of the window. In my experience, that''s not really that reliable though, so I forget how you do that, because I generally don''t try. If you store your sessions in the database and make sure there''s an updated_at column, then the updated_at column will the last time the user browsers sent a request to your app. So if they didn''t manually log out, you could look at that updated_at field. You could have a cron-job which periodically went through and says "if the user didn''t manually log out, but their session hasn''t been updated in an hour (or whatever), we''ll set their log out time to equal the session updated_at. But let''s say a user is staring at the same screen for an hour---the session updated_at might be an hour old, but they''re still staring at the screen. Well, you could use periodically_call_remote to have an AJAX function called every five seconds or whatever. As long as they are looking at that page, the AJAX function will be called every five seconds. If they stop, it will stop being called. So what does the function do? It doens''t have to do _anything_, as long as it contacts the server, session.updated_at will be updated, and then see the above paragraph again. Hope this gives you some ideas. Jonathan White Wizzard wrote:> I am writting an app that is going to record login times, logout times > and the session data of a user of the system. This will work if the > user manually logs out, but I would like it to record when the user > quits if the users exits the browser (or goes to a page not in our > application). Any ideas on how to accomplish this task? > > Any help is appreciated.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter De Berdt
2007-Sep-20 17:24 UTC
Re: Executing code when the user hits the X button on the browser
On 20 Sep 2007, at 16:58, White Wizzard wrote:> I am writting an app that is going to record login times, logout times > and the session data of a user of the system. This will work if the > user manually logs out, but I would like it to record when the user > quits if the users exits the browser (or goes to a page not in our > application). Any ideas on how to accomplish this task?There''s not out-of-the-box way (javascript doesn''t work, at least not for now), but you could do it with Juggernaut if it''s really important to you: http://ncavig.com/blog/?p=30#more-30 Haven''t tried it out, but it seems very nice. Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---