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 ?
Same-Origin policy is strictly enforced on Safari which means iframes with different domain names (or protocols or ports) will not be accessible while running automated tests.
In short, you can't, but you can set a cookie via JavaScript 😉 Safari on iOS supports localStorage, but in Private Mode it simply throws an error when you try to save anything to it, which is not great. Also it breaks the behaviour of your app on iPhones and iPads.
According to the W3C: Local storage is per origin (per domain and protocol). All pages, from one origin, can store and access the same data. In other words, if the iframes all reside in the same domain, then they will share the same local storage instance.
Why Safari doesn't allow to store cookie for iFrame? Answer: A: Answer: A: Try going to Safari/Preferences/Privacy and uncheck Prevent cross-site tracking.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With