DEV Community

John Stritzinger
John Stritzinger

Posted on

Accessing Local Storage variables from Javascript

ok.... I can read and write local storage variables via javascript with no problem as follows:

localStorage.set("testvariable", "3");
testvar = localStorage.get("testvariable);

And I can even verify these statements work from Developer Tools in Mozilla, Chrome, and Edge (They are ubiquitious).....

BUT

I write variables from my sso (sso.acme.com), and from my webroot (acme.com)

I need to write one function which can retrieve testvariable.sso.acme.com and testvariable.acme.com which are shown separately in the browser debug. (Yes I know cookies work too but I dont want to use that method for different reasons).

It appears there is a way to set your context to sso.acme.com before I call local.storage.get?

I wanna write something like.....
function parser()
{
setcontext(sso.acme.com); (this function doesnt exist??)
a = localStorage.getItem("testvariable);
setcontext(acme.com);
b = localStorage.getItem("testvariable);
c = a + b;
alert (c);
}

Top comments (0)