[英]Is it possible to use HTML5 local storage to share data between pages from different sites?
I would like to create data on the user side and let javascript from another URL access it too. 我想在用户端创建数据,让其他URL的javascript也可以访问它。 I am aware of the same origin policy, but I was wondering whether it is possible to create some exceptions. 我知道相同的原始政策,但我想知道是否有可能创建一些例外。 Or, is there any trick/feature I could use? 或者,我可以使用任何技巧/功能吗?
Best trick I know is to use iframes and postMessage
API do get access to localStorage from external domain. 我知道的最好的技巧是使用iframe和postMessage
API从外部域访问localStorage。
This technique is quite simple: 这种技术很简单:
your data domain need listen to message
event: 您的数据域需要侦听message
事件:
document.addEventListener ("message", handler, useCapture); document.addEventListener(“message”,handler,useCapture);
handler will be responsible for accessing localStorage
and posting its content to source domain handler将负责访问localStorage
并将其内容发布到源域
handler
function on data domain with postMessage
API https://developer.mozilla.org/en-US/docs/DOM/window.postMessage 您的源域可以使用postMessage
API调用数据域上的handler
函数https://developer.mozilla.org/en-US/docs/DOM/window.postMessage For security of your data you can use HTTP header X-Frame-Options ALLOW-FROM uri https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options?redirectlocale=en-US&redirectslug=The_X-FRAME-OPTIONS_response_header 为了保护您的数据,您可以使用HTTP标头X-Frame-Options ALLOW-FROM uri https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options?redirectlocale=en-US&redirectslug=The_X -frame-OPTIONS_response_header
Hope it will help. 希望它会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.