Reputation: 21062
I have a page with static elements, but some are added dynamically on load
event — let's say I populate the list of languages to pick. When the user select the language, and proceeds to the next page, and then gets back to the previous one, the list of languages will be built again, and the first item on the list will be selected, not the one user selected previously.
So my question is -- how (if it is possible) restore the previous state of the page?
Upvotes: 1
Views: 252
Reputation: 13560
You have three options.
1) Store the users selection in local storage and when the page loads read from local storage and populate your page accordingly.
2) When the user makes changes POST those changes to a web server and save the data in a session object or DB. Then when you first load the page again make an ajax call to GET the needed data from your server.
3) Write your page as a single page application and instead of navigating to a new page modify the page you have (e.g. hide one div and show another) such that you don't lose you data.
Upvotes: 1