在Safari和Safari移动设备上使用iframe localStorage [英] Iframe localStorage on Safari and Safari mobile

查看:710
本文介绍了在Safari和Safari移动设备上使用iframe localStorage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个javascript函数可以在我的页面的iframe中执行以设置本地存储。
在另一个页面上,托管在同一个域中的另一个iframe将尝试读取该值。
以下模式:

 域A 
| ---- iframe - 域B =>设置localStorage

域C
| ---- iframe - 域B =>阅读localStorage

这两个localStorage函数(读取和写入)托管在同一个域(域B)
在Safari和Safari移动版上,该值不会从页面A中的iframe传输到页面C中的iframe。
在Chrome和Firefox上运行良好。在Safari中,就好像iframe的localStorage特定于顶级页面域,并且不会跨页面传输,即使iframe域相同也是如此。
有没有人在safari上遇到与本地存储相同的问题?

解决方案

Safari的问题是由阻止Cookie和其他网站数据偏好设置为来自第三方和广告商默认情况下



更新:在Safari 8上,此选项为Cookies和网站数据:允许我访问的网站



预期行为仅在用户将此选项设置为从不时可用,如下图所示: http://i.stack.imgur.com/AP4ed.png



不幸的是 - 一个漏洞 - 设置的意图是明确的。

I have a javascript function that will execute in an iframe of my page to set a localstorage. On another page, another iframe hosted on the same domain will try to read the value. A schema below :

Domain A
  |---- iframe - Domain B => Set localStorage

Domain C
  |---- iframe - Domain B => Read localStorage

Both localStorage function (Read and Write) are hosted on the same Domain (Domain B) On Safari and Safari mobile, the value is not transmitted from iframe in page A to iframe in page C. It's working fine on Chrome and Firefox. In Safari, it's acting as if the localStorage of the iframe is specific to the top page domain and not transmitted accross pages, even if the iframe domain is the same. Does anybody is experiencing the same problem with local storage on safari ?

解决方案

The issue with Safari is caused by the "block cookies and other website data" preference which is set to "From third parties and advertisers" by default.

Update: on Safari 8, this option is "Cookies and website data: Allow from websites I visit".

The expected behaviour is only available if the user sets this option to "Never", as seen in the following picture: http://i.stack.imgur.com/AP4ed.png

It's unlikely that there is a loophole unfortunately - the intention of the setting is clear.

这篇关于在Safari和Safari移动设备上使用iframe localStorage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆