简体   繁体   English

如何使用不同域设置 iframe 的 SessionStorage

[英]How to set SessionStorage of iframe with different domain

I want to set the SessionStorage of an iframe which is located on my page.我想设置位于我的页面上的 iframe 的 SessionStorage。 However, the site in the iframe and my site have different domains.但是,iframe 中的站点和我的站点具有不同的域。 How can I handel that?我该如何处理? Thanks in advance: :)提前致谢: :)

  • If the iframe embed a content that have the same origin has your host website, they will share the same session storage.如果 iframe 嵌入与您的主机网站具有相同来源的内容,它们将共享相同的 session 存储。

  • If the iframe don't have the same origin as your host website, but you have control over it, you can maybe implement something with the postMessage API, to communicate with your iframe.如果 iframe 与您的主机网站的来源不同,您可以控制它,您可以使用postMessage API 实现一些东西,以与您的 iframe 进行通信。

  • If the iframe don't have the same origin as your host website, and you don't have control over it, you can't modify it's session storage for security reasons.如果 iframe 与您的主机网站的来源不同,并且您无法控制它,则出于安全原因,您无法修改它的 session 存储。

Take a look at this SO thread: sessionStorage in iframe for more info.看看这个 SO 线程: iframe 中的 sessionStorage了解更多信息。

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

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