Share dom storage between http and https

前端 未结 3 1472
走了就别回头了
走了就别回头了 2021-02-07 18:18

I would like a method of storing information on the client that can be accessed by both the SSL and nonSSL version of my site. localStorage is a great mechanism but it can only

3条回答
  •  名媛妹妹
    2021-02-07 19:15

    It's not technically possible as http as https schemes are deemed different origins as well as no-mix content limitations browsers has (now also in Firfox).

    From the specs (Web Storage):

    4.3.1 Security

    User agents must throw a SecurityError exception whenever any of the members of a Storage object originally returned by the localStorage attribute are accessed by scripts whose effective script origin is not the same as the origin of the Document of the Window object on which the localStorage attribute was accessed.

    So what is origin - lets look at CORS (Cross-Origin Resource Sharing) which states:

    ...origin is composed of [..] the scheme, hostname, and port.

    And further:

    https to http is not allowed.

提交回复
热议问题