首页 > 解决方案 > 仅具有本地范围 cookie 的沙盒 iframe

问题描述

是否可以加载可以运行脚本和写入 cookie 但不会覆盖父 cookie 的 sanboxed iframe?

例如,外部 HTML 将如下所示:

外部.html

  <html>
   .....
    <script>document.cookie='page=outer; path=/';</script>
    <iframe sandbox="<attribute-here>"  src="./inner.html"></iframe> 
   .....
  </html>

内部.html

  <html>
   .....
    <script>document.cookie='page=inner; path=/';</script>
   .....
  </html>

期望的结果是外部页面始终保留 cookie 值outer,而内部页面具有值inner

标签: javascriptsecuritycookiesiframesandbox

解决方案


推荐阅读