Mobile compatibility issues with sessionStorage

 

Recently, when developing mobile projects, there are many places where local storage is needed. It's just a matter of remembering the user data of the currently open window, so I chose to use sessionStorage.

The usage scenarios are as follows:

A.html page needs to record a piece of data {a: 1, b: 2};

sessionStorage.setItem("data","{a:1,b:2}");

 

B.html page is taken out and used;

sessionStorage.getItem ("data"); // The result is null

 

problem:

 

If the project is not a single-page multiple application, AB is two html files, you need to jump href. We will find that some browsers of the Andiron system are fetched on page B and the result is null (such as the window browser of the world that comes with vivo mobile phone).

 

the reason:

 

After analysis, it is not that this browser does not support sessionStorage, because you can still get the object of sessionStorage.

 

But because sessionStorage is a data storage format of the current window, some browsers open a new webView when they jump to a new page, and turn off the original, which is equivalent to we open a browser New window.

 

In this way, he will conflict with our sessionStorage principle, of course, it will not be available on the new page.

 

Therefore, it is recommended that you do not use sessionStorage if you are not a single-page multiple application project when you are doing mobile. Use with caution!

 

Guess you like

Origin www.cnblogs.com/liubingyjui/p/12720958.html