Reputation: 1854
My page has several sections and some of them can be changed on some js events e.g. sliders, pagination, filters. I need to store this data so that when the user navigates backwards and forwards using the browser history (back and forward buttons), the state is preserved. In other words, the user should see a page in the same state as they left it when they clicked away.
As there are several sections driven by js events, I don't want to use the html5 history feature because the url would become too messy and wouldn't add any valid information when sharing the page with another person.
So in plain words, I would like to restore or keep the state of a page without changing the url. Is there a clear way of implementing this?
Thanks.
Upvotes: 3
Views: 811
Reputation: 64933
You could save those values in the local storage/session storage. You could also AJAX post the data to the server, and rebuild this data when going through forward/backward.
Upvotes: 0
Reputation: 382464
You may use localStorage to store properties that you'll be able to read next time.
Write :
localStorage['key'] = 'value';
Read :
var val = localStorage['key'];
Read with default value (for first connection for example) :
var val = localStorage['key'] || 'default value';
Upvotes: 4