1

We all know when we close the last tab in chrome , chrome closes as well. As a user, I want a confirmation when it is the last tab open.

Showing a confirmation on close is easy. window.onbeforeunload = function(e) { } does the job.

BUT HOW DO I KNOW ITS THE LAST TAB OR NOT, OR GET THE COUNT OF TABS OPEN IN CHROME.

Paki
  • 25
  • 1
  • 5
  • 1
    I don't think it's possible for a website to know how many tabs are left. – evolutionxbox Mar 24 '21 at 13:36
  • 2
    Does this answer your question? [Is there any way to count number of tabs are opened in chrome?](https://stackoverflow.com/questions/42109296/is-there-any-way-to-count-number-of-tabs-are-opened-in-chrome) – evolutionxbox Mar 24 '21 at 13:37
  • You can write to localstorage on each tab when page loads and exits. Not going to catch when the user just closes the browser. – epascarello Mar 24 '21 at 13:48
  • @epascarello I understand we can localStorage to have counter or keep track of tabs open, but i will never know if there is another tab open from other website. I can implement it only when its the last tab of my site. – Ravin Mohanraj Mar 24 '21 at 13:59
  • @evolutionxbox No, been to the solution suggested, a website will not have access to chrome.tabs. Same time, using localStorage to keep track will track only my tabs. Will never know if there is another tab from another site open. – Ravin Mohanraj Mar 24 '21 at 14:01
  • Just to double-check, you're not writing an extension? – evolutionxbox Mar 24 '21 at 14:02
  • Correct, not an extension. Trying to figure out tabs open from a react application. @evolutionxbox – Ravin Mohanraj Mar 24 '21 at 14:08
  • If it's not an extension I think the answer, sadly, is "it's not possible". https://softwarerecs.stackexchange.com/a/10668 – evolutionxbox Mar 24 '21 at 14:17
  • Why would you care if it is the last website opened or not? Seems like an odd requirement. – epascarello Mar 24 '21 at 14:59

0 Answers0