sessionStorage in iframe

后端 未结 2 1001
逝去的感伤
逝去的感伤 2021-01-05 03:46

I\'m going to have several iframes on my page and I\'m going to quite intensively use sessionStorage inside them. What I\'m curious about is if I will have separate storages

2条回答
  •  星月不相逢
    2021-01-05 04:05

    If sessionStorage is shared depends on the iframe's page and it's origin, which is the domain part of the URL. If you have a webpage at http://myserver/test.html and it is including http://thatserver/some.html via an iframe, the iframe's page has the domain thatserver. Thus the origin differs and the sessionStorage won't be shared. But if the iframe's page is http://myserver/some.html it has the same origin and therefore will share the same session storage.

    Now there is an additional trick: The sandbox attribute for the iframe. If you write