I have a nice Logout button on the menu of my PHP app, but some people don't use it, they just quit the browser.
Is there any way that I can detect this (I realize that it won't handle browser crash, but it's better than I have now & covers 99% of cases).
This will be my first piece of JS.
- I presume that I can easily write a page close handler? Or should I use onbeforeunload()?
- In it, maybe I can walk all browser windows and their tabs (same or different for each browser? (IE, FF, etc))
- I can get the URL of each tab and check if it is running my app (or is there a better way to do it)?
- If this is the last tab, either load a new age which is my app’s logout page, then close it (waiting for it to fully open? Or just send an HTTP request and wait for 200 OK), or maybe some Ajax?
Update
No timer based solutions, please. I have one in place, but a single user set the timeout to 999999 minutes and the number of simultaneous users to 1, then closed his browser & locked himself out
Update
It seems that those here who know say that it can't be done in JS, and Google suggests to me that is isn't supported in the DOM.
But, what about another way? Think laterally, folks. Can I push a cookie when the user opens a new tab with a page from my app? And then remove the cookie when the user wishes to close the tab? And check if I am remvoing the last cookie & inform the server to treat this as logout?
If not cookies is there some other method? (Use Ajax on page open & close and the server can decide if the last tab has closed?)