I read some documentation on sessionStorage and localStorage, but I don't understand what the scope is: the domain, a specific page?
For example, if I have the following pages:
http://example.com/products.aspx?productID=1
http://example.com/products.aspx?productID=2
http://example.com/services.aspx?serviceID=3
And if on each of the above pages I run (with idvalue being the value in the querystring):
localStorage.setItem('ID',idvalue);
Am I going to end up with 3 different values stored, or are the values going to overwrite each other?
localStorage is similar to sessionStorage , except that while localStorage data has no expiration time, sessionStorage data gets cleared when the page session ends — that is, when the page is closed.
Session storage is a popular choice when it comes to storing data on a browser. It enables developers to save and retrieve different values. Unlike local storage, session storage only keeps data for a particular session. The data is cleared once the user closes the browser window.
The difference between sessionStorage and localStorage is that localStorage data does not expire, whereas sessionStorage data is cleared when the page session ends. A unique page session gets created once a document is loaded in a browser tab. Page sessions are valid for only one tab at a time.
localStorage and sessionStorage are almost identical and have the same API. The difference is that with sessionStorage , the data is persisted only until the window or tab is closed. With localStorage , the data is persisted until the user manually clears the browser cache or until your web app clears the data.
Session Storage:
Values persist only as long as the window or tab in which they stored.
Values are only visible within the window or tab that created them.
Local Storage:
Values persist window and browser lifetimes.
Values are shared across every window or tab running at the same origin.
So, by reading and understanding this each key-value pair is unique for each domain, because local storage persist values across window or tab.
The values are going to overwrite each other. Each key-name pair is unique for a protocol and domain, regardless of the paths.
The affected domain can be changed via the document.domain
property.
sub.example.com
-> example.com
is possible (subdomain)sub.example.com
-> other.example.com
is not possibleIf 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