The difference between localStorage and sessionStorage

LocalStorage, like sessionStorage, is an object used to store temporary client information. It is HTML5 that provides two new methods for storing data on the client, both of which are only stored in the client (ie browser) and do not participate in the communication with the server.

They can only store objects of string type (although other primitive types of objects can be stored in the specification, no browser has implemented them so far).

The localStorage life cycle is permanent, which means that unless the user clears the localStorage information on the UI provided by the browser, the information will always exist.

The life cycle of sessionStorage is the current window or tab. Once the window or tab is permanently closed, all data stored in sessionStorage will be emptied.

Different browsers cannot share information in localStorage or sessionStorage. Different pages of the same browser can share the same localStorage (pages belong to the same domain name and port), but different pages or tabs cannot share sessionStorage information. It should be noted here that pages and tabs only refer to top-level windows. If a tab contains multiple iframe tags and they belong to the same source, then they can share sessionStorage.

Guess you like

Origin blog.csdn.net/weixin_42201180/article/details/109721570