I have two domains domain1.site.com and domain2.site.com, i have set session-storage in domain1.site.com and then not able to get session-storage on other domain domain2.site.com from same tab. Is there any other way which can be used identify a tab when navigated across sub-domains?
The question is a bit older, but maybe the following helps others.
There is a solution called "Cross Domain Local Storage", it works with a combination of localStorage and postMessage. With that you have a storage you can use with any domain. There are two projects that I know:
But that's not a session storage. To separate multiple tabs, you have to generate a unique id (maybe tab creation date in milliseconds) and save that into the session storage, but only the first time, when there is no value already in the session storage. That way you have one id per tab. That id you can use to put data into the cross domain local storage.
As @PaulS mentioned in his comment, you most likely mean to use localStorage
.
That said, you are still hindered by the Same Origin Policy.
If your example is correct, and both sites share the same top-level domain such as:
domain1 .example.com
domain2 .example.com
Then you can set document.domain = "example.com";
to allow the two to share information.
More detail on MDN: https://developer.mozilla.org/en-US/docs/Web/API/document.domain
sessionStorage
instead of localStorage
to fulfill that purpose. And i have already tried to set the document.domain
to a common top-level domain and checked the sessionStorage
, it didnt work. –
Shepherd document.domain
to? That combo really should work. –
Cheese document.domain
to top-level domain as you have mentioned, but i am checking the `sessionStorage'. Btw i tried this on Chrome. –
Shepherd document.domain
. –
Sporty © 2022 - 2024 — McMap. All rights reserved.
sessionStorage
doesn't go across concurrent tabs anyway, you probably wantlocalStorage
for this. Secondly, no; these are of different origin so they don't share this. You may, however, be able towindowRef.postMessage
data from one to the other – Intercalation