Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6699029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:38:49+00:00 2026-05-26T06:38:49+00:00

I have a nice Logout button on the menu of my PHP app, but

  • 0

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?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:38:49+00:00Added an answer on May 26, 2026 at 6:38 am
    1. You can add some code that gets executed when a page is closed in onbeforeunload. Browsers may abort your code, though, if it takes too long.
    2. No, you cannot iterate through tabs; that would be a security hole.
    3. No; since you cannot iterate through tabs, you cannot get their URLs either.
    4. You cannot detect if it’s the last tab with your page open, but if you could, a browser would likely block opening a window on closing a tab. A synchronous AJAX request may work, however.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a nice LogOut button on the menu of my PHP app, but
I have a nice and lovely Django site up and running, but have noticed
I have a nice DataGridView showing what is basically some kind of log data
I have this nice little MSBuild-based daily build setup that I use on my
IE have nice feature: if you right-click on some link you will see an
I don't have much experience with web.config files but what I am trying to
I don't have nice short code examples to display with this post. I'm running
I'm using devise for user auth, but I have nice mockups for the signup,
I have, I believe, a simple problem, but I don't know how to solve
In order to have nice clean urls with some kind of site archetecture I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.