I need to store some data client side and this data is too large to store it in a cookie. LocalStorage seemed like the perfect way of doing this but the thing is that the website that i will be using this has some parts that work on https and others with just http and as local storage can’t access data from https that you set with http this doesn’t seem like a viable solution anymore.
Any idea if there is any solution to this? Any other alternatives?
Store all data on one domain, e.g.
https://my.domain.org/.httpsprotocols, simply uselocalStorage.setItem('key', 'value')to save the data.httpprotocols, embed ahttpsframe, and usepostMessageto save the data:Demo: http://jsfiddle.net/gK7ce/4/ (with the helper page being located at http://jsfiddle.net/gK7ce/3/).
On the http(s) page, the frame can be embedded as follows (replace
https://my.mydomain.comwith the actual URL. Note that you can simply get a reference to the frame, and use thesrcattribute):Note that the method is asynchronous, because of
postMessage. An implementation of thegetItemmethod has to be implemented differently:Note that each callback is stored in a hash. Each message also contains an identifier, so that the window which receives the message calls the correct corresponding callback.
For completeness, here’s the
LSremoveItemmethod: