简体   繁体   中英

Share LocalStorage/SessionStorage between different domains in (angular 6)

在 Angular 6 中,当我将数据存储在本地存储 (localhost:4200) 中,但是当我们可以运行像 (abc.localhost:4200) 这样的子域时,在本地存储中删除了数据,请帮我解决这个问题

您可以使用跨存储跨域存储npms

In short. No.

This is the definition of localStorage specification. As Mozilla said ;

The read-only localStorage property allows you to access a Storage object for the Document's origin;

and there are some examples of what is Document origin.

Data stored to domain.com can not be accessed from sub.domain.com as per the standards. So you cant access local storage of localhost:4200 from abc.localhost:4200 no matter what you do. But to overcome this you may use solutions suggested by these posts,

https://jcubic.wordpress.com/2014/06/20/cross-domain-localstorage/

Can HTML5 databases and localStorage be shared across subdomains?

use localStorage across subdomains

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM