37

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 ?

2
  • Yea, I got the same issue here..
    – adardesign
    Dec 9, 2013 at 16:10
  • Yep same issue, I'd like to see some documentation but haven't found any
    – robC
    Mar 13, 2014 at 18:02

1 Answer 1

19

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: https://i.stack.imgur.com/AP4ed.png

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

4
  • Does anybody know how to share localStorage data between domains when "From third parties and advertisers" is set? Jul 31, 2014 at 14:57
  • 2
    this not right. because there are websites like disqus and facebook like button setting so many variables in localstorage and cookies. there has to be a way,
    – Sahan
    Jun 18, 2016 at 20:35
  • 2
    How come "cookies" are accessible not "localStorage" ? definitely a bug, safari should fix it.
    – Darshan
    Sep 6, 2016 at 21:26
  • There ARE workarounds. See: stackoverflow.com/a/64018207/5243309 Aug 7 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.