The question says it all. I realize that all options do work in up-to-date browsers, but what is the semantically best choice, and why?
Supposedly, window. localStorage makes the localStorage faster to be found than just writing localStorage. Storing a reference to it on a variable makes it even faster. Anyway, these improvements are negligible on modern browsers.
The localStorage read-only property of the window interface allows you to access a Storage object for the Document 's origin; the stored data is saved across browser sessions.
The major methods in local storage are setItem , getItem , removeItem and clear . A key is required when storing, retrieving, and removing items from the local storage.
Any content/data saved to the localStorage object will be available after the browser has been restarted (closed and opened again). In order to save an item to localStorage , you can use the method setItem() . This method must be handed a key and a value.
According to W3C standards, the correct is window.localStorage
because the localStorage
attribute is part of window object. And it is not a function, it is an attribute.
Source: http://dev.w3.org/html5/webstorage/#dom-localstorage
Example: http://www.rajdeepd.com/articles/chrome/localstrg/LocalStorageSample.htm
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