Javascript 来自iframge的Firefox localstorage-SecurityError:操作不安全
我有2个子域:Javascript 来自iframge的Firefox localstorage-SecurityError:操作不安全,javascript,firefox,Javascript,Firefox,我有2个子域: www.example.com=仅适用于登录用户 internal.example.com=公共网站 由于我使用localstorage在internal.example.com上存储我在www.example.com上需要的一些信息,因此我实现了以下解决方案: 我在www上加载位于内部的iframe。我在两侧将文档域值设置为“父域” 现在在www上,我可以通过以下操作访问internal over www的本地存储: frames['internalFrameName'].
- www.example.com=仅适用于登录用户
- internal.example.com=公共网站
frames['internalFrameName'].window.localStorage;
现在我可以读写值了。这在Chrome和Internetexplorer中有效,在Firefox中有效,直到最后一次更新到FF30。现在我得到一个错误:
SecurityError: The operation is insecure.
有没有办法解决这个问题?您可以使用消息系统在两个帧之间进行通信。然后iframe就可以向您发送本地存储数据 这可能对您有所帮助:
您需要使用frames['internalFrameName'].postMessage(message,targetOrigin,[transfer]) 禁用Cookie时,Gecko会抛出错误消息,因此除了对
localStorage
进行对象检测之外(我确信您在未发布的代码中进行了此操作),首先检查是否支持Cookie
更改:
if (window.localStorage)
致:
if (window.localStorage)
if (document.cookie && window.localStorage)