2

(I am developing a Node.js/Express web application.)

Is there a way to identify a tab and have its identifier saved locally in the browser so that the identifier is persistent across different pages of the same web site?

Example, my web application is opened by the user in two tabs of the same browser. I would like to know that they are opened in different tabs. Even if the user in tab A presses F5 to refresh the page, I (in the client Javascript) would like to know that the page is still in tab A.

Is there a property of window or another object in the DOM that identifies the browser tab?

Old Geezer
  • 14,854
  • 31
  • 111
  • 198

1 Answers1

2

Nothing simple. However, there are two interesting technologies that may help you solve your problem.

sessionStorage is the closest to what you described. It gives each tab a different Storage object that you can store random IDs in. It doesn't quite work though, because when you open a link in a new tab the second tab gets a copy of the parent page's sessionStorage object, including whatever you stored in the parent page's sessionStorage.

The storage event is probably what you want to use. You can have your tabs communicate directly with each other to coordinate unique IDs or detect multiple tabs being open. See this question which is focused on how to communicate across tabs in javascript.

Some combination of these two technologies will probably help you solve whatever you are trying to accomplish.

JosiahDaniels
  • 2,411
  • 20
  • 37