How can I keep javascript objects alive in a multi-page app (browser independently)?
I know I can for example write a Chrome extension with a background page that would solve it, but is there a browser independent way for this?
How can I keep javascript objects alive in a multi-page app (browser independently)?
I know I can for example write a Chrome extension with a background page that would solve it, but is there a browser independent way for this?
One approach is to have your javascript code load the pages (via 'ajax' calls) and then replace the body of the html, or parts of it. This way, as far as the browser is concerned you're still on the same "page". You'll have to make sure all the links within your website are void and instead of causing a browser page load, they actually trigger a javascript function. This is the way Facebook, for example, manages clicks on its website. See https://stackoverflow.com/a/7425870/562906
As you are using html5 you could use local storage to store JSON representations of your objects:
var json_text = JSON.stringify(your_object, null, 2);
localStorage.setItem("someKey", json_text);
and then to retrieve your item when on the other page:
var your_object = JSON.parse(localStorage.getItem("someKey"));
To use JSON.stringify you may need JSON-js - if the browser does html5 it appears likely that you won't need the third party script.