【问题标题】:localStorage.clear() in Iframe also clear the localStorage of Main PageIframe 中的 localStorage.clear() 也会清除 Main Page 的 localStorage
【发布时间】:2014-03-07 00:06:00
【问题描述】:

我正在使用实时编辑器并使用HTML5 localstorage 将一些重要数据存储在我的Main Page 上,

我的Main Page 上有一个Iframe,它在同一个域上工作,用于显示编辑器的结果,这里的问题是,每当我编写 JS 代码时:

喜欢:

localStorage.clear();

到我的编辑器并在我的 iframe 上运行它,然后它也会清除我的 localStorage 主页。

我如何纠正这个问题?

我正在使用字符串将我的代码发送到iframe

iframe.contentWindow.document.head.appendChild(Script);

Script 包含一个带有User Codescript tag,它只会在iframe 中运行! 但是为什么我的localStorage.clear(); 还有clear 存储的主页数据?

答案将非常感谢!

【问题讨论】:

    标签: javascript html iframe local-storage


    【解决方案1】:

    这里或多或少有答案:

    In HTML5, is the localStorage object isolated per page/domain?

    localStorage 是每个域的。

    【讨论】:

    • 你说得对,但是有没有不使用密钥的解决方案来防止我的主页本地存储?
    • 不。 clear() 清除(使用柠檬的力量)。您可以完全使用子域或其他域。但是我猜你还有其他问题。
    猜你喜欢
    • 2013-12-04
    • 1970-01-01
    • 2012-12-08
    • 2011-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多