0

I am trying to clear cookies when all tabs of same site is closed. when browser is closed i can do this but cant it for tabs. i dont want to clear cookies after closing just one tab, i want to do that when last tab of same site is closed in a browser.

would you give any efficient suggestion.

I am doing my backend in php Laravel.

mare96
  • 3,749
  • 1
  • 16
  • 28
  • Given PHP has no concept of a browser tab since it runs on the server, this isn't possible with only PHP. I'm not even sure how possible it would be with JS. I don't know for sure, but I doubt you'd have access to other tabs by default. – Jonnix Jul 23 '19 at 07:43
  • I think he only wants it to trigger on his site – Nico Bleiler Jul 23 '19 at 07:49
  • @NicoBleiler Does that make a difference? – Jonnix Jul 23 '19 at 07:58
  • https://stackoverflow.com/questions/23690666/check-if-my-website-is-open-in-another-tab has suggestions on how to check if your site is open in other tabs. There’s couple more with similar topics, https://www.google.com/search?q=find+out+if+website+opened+in+other+tabs+site:stackoverflow.com – misorude Jul 23 '19 at 08:43
  • @Jonnix Yes, that you could handle with JS, onbeforeunload. – Nico Bleiler Jul 23 '19 at 09:24
  • @NicoBleiler I don't see how `onbeforeunload` would help seeing if the site was open on another tab? The local storage option does seem doable though, which I guess you could tie in to that event, but that didn't seem to be what you were suggesting. – Jonnix Jul 23 '19 at 09:27

1 Answers1

0

You have to use JS to do that, but it is not reliable.

The onbeforeunload triggers on page, tabclose and more.

https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload

Nico Bleiler
  • 475
  • 4
  • 14