开发者

Safari Local Storage is empty when terminated and started

开发者 https://www.devze.com 2023-03-09 00:55 出处:网络
I am writing a simple value to Safari\'s local storage, if Safari is then shut down it will be able to read the value in question.

I am writing a simple value to Safari's local storage, if Safari is then shut down it will be able to read the value in question.

Interestingly I am able to write the data to local storage with the following code:

localStorage.setItem("savedData", JSON.stringify(cookieValue));

But when I close all instances of Safari and open a new one the local storage is shown as empty.

Does anybody kno开发者_StackOverflow中文版w why this would happen?


The solution is rather obvious, it was my mistake from omitting some of the finer details; essentially the browser is trying to keep the secure data away from the insecure data.

The page that tries to store the data is http, whereas the page that tries to retrieve the data is https.

localStorage is the same as globalStorage[location.hostname], with the exception of being scoped to an HTML5 origin (scheme + hostname + non-standard port) and localStorage being an instance of Storage as opposed to globalStorage[location.hostname] being an instance of StorageObsolete. For example, http://example.com is not able to access the same localStorage object as https://example.com but they can access the same globalStorage item. localStorage is a standard interface while globalStorage is non-standard. localStorage was introduced in Firefox 3.5.

From Mozilla - DOM Storage

I'm assuming this concept applies to all browsers, then again it's only an assumption.

Hope this helps people who may be in the same situation.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号