I would like a method of storing information on the client that can be accessed by both the SSL and nonSSL version of my site. localStorage is a great mechanism but it can only
The way I did this was to use an iframe that does a postMessage to its parent. The iframe is always on https but the parent can be either http or https. This solution assumes the modifications are on SSL only to the storage and syncs it back for non SSL but you could adapt this to send modifications both ways so the non ssl parent sends changes down to the ssl child.
ssl iframe source (storage-sync.html):
if (sessionStorage.cart)
try {
var obj = { cart: JSON.parse(sessionStorage.cart) };
parent.postMessage(JSON.stringify(obj), 'http://yourdomain.com');
} catch(ex) {
console.log(ex);
}
ssl/non ssl parent source:
window.addEventListener('message', function(ev) {
if (ev.origin !== 'https://yourdomain.com')
return;
try {
var obj = JSON.parse(ev.data);
sessionStorage.cart = JSON.stringify(obj.cart);
cart.reload();
} catch(ex) {};
});
$('body').append('');
Placing the target origins to the right protocols ensures you won't be sending messages to wrong ones.