简体   繁体   English

嵌入 reactjs 应用程序以访问本地存储

[英]Embed reactjs app with access to localstorage

I have a Reactjs app that uses localstorage, I would like users to be able to embed my website.我有一个使用本地存储的 Reactjs 应用程序,我希望用户能够嵌入我的网站。

I would like to access the localstorage for my website when it is embedded, but I get the following message twice:我想在我的网站嵌入时访问它的 localstorage,但我收到以下消息两次:

DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document. DOMException:无法从“Window”读取“localStorage”属性:此文档的访问被拒绝。

I also use the localstorage when users use my website normally.当用户正常使用我的网站时,我也会使用 localstorage。

How can I check localstorage of my own website when it is being embedded via iframe?当我自己的网站通过 iframe 嵌入时,如何检查它的本地存储

Preferrably I would like to know how I can do it within the realm of reactjs, worst case, I can just never check local storage and they can login from the embed.最好我想知道如何在 reactjs 领域内做到这一点,最坏的情况是,我永远无法检查本地存储,他们可以从嵌入中登录。

If it is impossible, would I be able to check cookies via react in an iframe?如果不可能,我是否可以通过 iframe 中的反应来检查 cookie?

If you are using brave, you must "allow all cookies" enabled, or cross-site cookies will be blocked.如果您使用勇敢,则必须启用“允许所有 cookie”,否则跨站点 cookie 将被阻止。 An embed accessing localStorage is considered cross-site cookie in this case and will be blocked, so you can try to access local storage and if you get that error your app knows it is in an embed.在这种情况下,访问 localStorage 的嵌入被视为跨站点 cookie,将被阻止,因此您可以尝试访问本地存储,如果出现该错误,您的应用程序知道它在嵌入中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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