[英]Accessing localStorage for a domain via iframe
On example.com
I have an iframe which loads anotherexample.com
.在
example.com
上,我有一个anotherexample.com
加载了另一个 example.com 。 The problem I am having though is if I load anotherexample.com
directly (outside of the iframe) the localStorage isn't shared with the iframed anotherexample.com
.我遇到的问题是,如果我直接(在 iframe 之外)加载
anotherexample.com
,localStorage 不会与 iframed anotherexample.com
共享。
Is this possible to achieve?这有可能实现吗?
An example of the issue can be seen by visiting https://eskimo.dev/localstorage/ , then visiting https://eskimo.ooo/localstorage/iframe which iframes the first link.通过访问https://eskimo.dev/localstorage/可以看到该问题的示例,然后访问https://eskimo.ooo/localstorage/iframe iframe 第一个链接。 The iframe isn't using the localStorage from the previous.
iframe 没有使用之前的 localStorage。
Actually I tried, and it worked for me (I accessed first /iframe
but it worked for me both ways):实际上我试过了,它对我有用(我先访问
/iframe
但它对我两种方式都有效):
Image from https://eskimo.ooo/localstorage/iframe图片来自 https://eskimo.ooo/localstorage/iframe
Image from https://eskimo.dev/localstorage/图片来自 https://eskimo.dev/localstorage/
Image from DevTools图片来自 DevTools
Of course, when I disabled all third party cookies it didn't work.当然,当我禁用所有第三方 cookies 时,它没有用。 Might that be the reason?
这可能是原因吗?
I'm using chrome 107.0 by the way.顺便说一下,我使用的是 chrome 107.0。
Not sure why its not behaving as it should.不知道为什么它的行为不正常。 May be code snippets might be really helpful here.
可能代码片段在这里可能真的很有帮助。 But by the above linked example in the OP.
但是通过 OP 中的上述链接示例。 The reason its not working there is:
它在那里不起作用的原因是:
What will work?什么会起作用? :
:
Because, the domain origin is not changing, hence it can access the same localStorage.因为,域源没有改变,因此它可以访问相同的 localStorage。
Thanks谢谢
It is a complete other domain, so there is no way access localStorage of the other domain.它是一个完整的其他域,因此无法访问其他域的localStorage。
But if you have control of both domains, you could use javascript events to share the localStorage through domains.但是,如果您可以控制这两个域,则可以使用 javascript 事件通过域共享 localStorage。
You can see more here: cross domain localstorage with javascript你可以在这里看到更多: cross domain localstorage with javascript
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.