I have a task in which I need to transfer the value of a variable from a subdomain to a domain. I am using localstorage
. I have a domain, and I have a subdomain, which means that each has its own script file, template file, etc.
In the subdomain script file, I write the following, i.e. I put the value of the variable into the localstorage cell:
/subdomain script file/
localStorage.setItem("city_id", city_id);
In the domain script file, I am trying to get this value like this:
/domain script file/
var result = localStorage.getItem("city_id");
console.log(result);
But the console displays undefined
.
Has already worked with localstorage, and more than once. But one thing is not clear to me, if this is a browser storage, then there is no difference where you enter the value, and where you try to get it (I'm talking about different script files).
Maybe I missed something, or I don't fully understand how localstorage works. If localstorage does not work that way, please tell me other methods of transferring the value of a variable from a subdomain to a domain, or vice versa. Thank.