4

Scenario:

We have one analysis which gives different results based on different inputs. So if the user open the same analysis in two different browser tabs, the session variables being common will get overridden and output will be same in both tabs though we want different outputs based on different user inputs in tabs.

So we plan to send a tab-id at the backend so that we save session variables per tab-id.

Is there some automatic way that tab information is being sent to the server like may be in request header or something like that?? Or we will have to generate a tab-id ourselves and send it with every request?

Siddharth Trikha
  • 2,648
  • 8
  • 57
  • 101

1 Answers1

2

You'll have to generate your tab-id and pass it back with each request, but the following might make it a bit easier:

You can use sessionStorage from Web Storage API to store values unique to each tab. Every tab in the browser starts a new session so they are always distinct.

https://developer.mozilla.org/en/docs/Web/API/Window/sessionStorage

It should work with most common browsers (even IE8+): http://caniuse.com/#search=web%20storage

Hope that helps!

beercohol
  • 2,577
  • 13
  • 26
  • As far as I understand, `sessionStorage` is a client side session to save information on client. In my case I want server side session variables to be identified differently per tab. Any suggestion regarding that?? – Siddharth Trikha Jun 03 '15 at 09:39
  • 2
    That's correct, sessionStorage is client side. The thing that makes it useful to you here is that it's unique for each tab. So you can have a bit of script on your page that generates your unique tab-id and keeps it in sessionStorage, then passes that back to the server with each request. You can then use the tab-id on the server to make your session vars unique, e.g. store them in an array indexed by the tab-id, or even just append it to the var name. – beercohol Jun 03 '15 at 11:26
  • See here for some info on how to generate UUIDs in Javascript: http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript Look below the accepted answer to the one from @broofa – beercohol Jun 03 '15 at 11:33