log out a user when user closes tab or browser

969 views
Skip to first unread message

Sam W

unread,
Mar 21, 2019, 1:34:12 AM3/21/19
to Django users
Is there a way in Django to log out a user when user closes tab or browser? This one "SESSION_EXPIRE_AT_BROWSER_CLOSE =True" Doesn't work

Christian Ledermann

unread,
Mar 21, 2019, 7:48:20 AM3/21/19
to django...@googlegroups.com
SESSION_EXPIRE_AT_BROWSER_CLOSE works for me
but only when you close the browswer, closing a tab will not log you out
also it depends on the browser (firefox seemed in the past to ignore this)

On Thu, 21 Mar 2019 at 05:34, Sam W <samc...@gmail.com> wrote:
Is there a way in Django to log out a user when user closes tab or browser? This one "SESSION_EXPIRE_AT_BROWSER_CLOSE =True" Doesn't work

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/644cca74-0443-4c71-8d8e-7326a252eb2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Best Regards,

Christian Ledermann

Newark-on-Trent - UK
Mobile : +44 7474997517

https://uk.linkedin.com/in/christianledermann
https://github.com/cleder/


<*)))>{

If you save the living environment, the biodiversity that we have left,
you will also automatically save the physical environment, too. But If
you only save the physical environment, you will ultimately lose both.

1) Don’t drive species to extinction

2) Don’t destroy a habitat that species rely on.

3) Don’t change the climate in ways that will result in the above.

}<(((*>

Mohammad Etemaddar

unread,
Mar 21, 2019, 9:46:22 AM3/21/19
to django...@googlegroups.com
I have a suggest for you. Its non standard.

First create a javascript infinite loop to make a get call every 1 minute.
Also make session expiration time at 2 minutes. So if tabs closed the session will expire at 1 minute.

Sam W

unread,
Mar 21, 2019, 10:02:24 AM3/21/19
to Django users
Thank you for your response. 
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
Doesn't work well in Chrome browser. Plus I want the client's session
to be expired/logged out when tab closed.

Sam W

unread,
Mar 21, 2019, 10:05:46 AM3/21/19
to Django users
Thank you for your response. 
JavaScript infinite loop behavior gets blocked by Antivirus.

KadirCEBEL

unread,
Mar 21, 2019, 10:17:38 AM3/21/19
to django...@googlegroups.com
You can use jquery. you can write a function like logout (in the view)
after that when browser tab is closed (you have to check with jquery
code) you can kill user session.

Prş, 2019-03-21 tarihinde 17:15 +0330 saatinde, Mohammad Etemaddar
yazdı:
Teşekkürler,
http://www.kadircebel.com

Marconi Moreto Jr.

unread,
Mar 21, 2019, 10:46:45 AM3/21/19
to django...@googlegroups.com
How about on `window.onbeforeunload` you delete the session id from the cookie, on next visit no session id to send so should be considered logged-out.
> https://groups.google.com/d/msgid/django-users/07d89baa005bb001a3c2b034b073264edd05c40c.camel%40gmail.com.
Reply all
Reply to author
Forward
0 new messages