I want to pass some data between different tabs using sessionStorage on my local server. I have tried some ways but could not succeed. Anyone please help me.
This is my one file where I am setting my data.
if (typeof(Storage) !== "undefined") {
var loggedInUserId = loggedInId;
console.log(loggedInUserId);
sessionStorage.clear();
sessionStorage.setItem("loggedin_id", loggedInUserId);
console.log(sessionStorage);
}
and I am trying to fetch the data from other file of another project of my local drive
var companyId = sessionStorage.getItem("loggedin_id");
The problem is, data is setting on the browser but when I check on my other project tab the storage remain empty.
note: my two projects are in two drives, dont know its makes difference or not. Please anyone give me some way to solve it. thank you .
Session storage is not the appropriate tool for your task you should be using local storage For sessionStorage, changes are only available per window (or tab in browsers like Chrome and Firefox)
in your case you want the data to be shared throughout different tabs so you can do something like this :
if (typeof(Storage) !== "undefined") {
localStorage.setItem("firstname", "fady");
} else {
// Sorry! No Web Storage support..
}
and then you can retrieve it just the same you did with your session storage
var firstname = localStorage.getItem("firstname");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With