When is SessionStorage reset?

WBOY
Release: 2024-01-13 10:55:06
Original
810 people have browsed it

When is SessionStorage reset?

SessionStorage will be cleared under the following circumstances:

  1. Close the browser: When the user closes the browser window, all SessionStorage data will be cleared. This is because SessionStorage is temporarily stored in the browser memory and will be automatically cleared after the browser is closed.
  2. Session end: SessionStorage is associated with the browser's session. When the session ends, SessionStorage will also be cleared. Specific situations when the session ends include the user actively logging out, logging out, or the session expires.
  3. Manual clearing: Through JavaScript code, you can manually clear the data in SessionStorage. The following is a specific code example:
// 添加数据到SessionStorage
sessionStorage.setItem('name', 'John');
sessionStorage.setItem('age', '25');

// 手动清除SessionStorage中的数据
sessionStorage.removeItem('name');
Copy after login

In the above code example, we first use the sessionStorage.setItem() method to separate name and age Stored in SessionStorage. Then, through the sessionStorage.removeItem() method, we manually clear the value of the name key.

  1. Page jump or refresh: When the page jumps or refreshes, the data in SessionStorage will be retained and can be used in other pages in the same session. However, if you jump to a new domain name or close all browser tabs related to the current domain name, the data in SessionStorage will be cleared.

It should be noted that SessionStorage is based on domain name. Pages between different domain names or different second-level domain names cannot share SessionStorage. Each domain name has an independent SessionStorage.

The above is the detailed content of When is SessionStorage reset?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!