0

How to keep the current HTML content on my page after refresh? (which solutions are currently the most used?)

I have simple HTML page, and a JavaScript function that loads dynamically HTML controls in my page when a button is clicked. But, after refresh all those added controls are lost. How do I keep them after refresh?

Thank you

web_dev15
  • 1
  • 1
  • 1
    don't refresh - use AJAX and keep the page content throughout – gavgrif Jun 26 '16 at 02:19
  • I'm not exactly sure what you're asking, but it sounds like you're needing to save the user's settings to some sort a database, so when the page is 'refreshed', you can then use Ajax to load the saved controls back onto the page. – user1661677 Jun 26 '16 at 02:24
  • yes I do use AJAX to load html file from server. But the problem then is, how to keep the new html that was added to my page, after refresh? – web_dev15 Jun 26 '16 at 02:24
  • user1661677: I am reading about other technologies, maybe Web Storage is better than using a database? – web_dev15 Jun 26 '16 at 02:25
  • I highly recommend localStorage for this usage. You can set key:value pairs up and simply repopulate any fields you need to return on a refresh. It will allow you to save information for a refresh and not need a db. See this page for information on how to use localStorage http://stackoverflow.com/questions/2010892/storing-objects-in-html5-localstorage – JoeCrash Jun 26 '16 at 05:11
  • See http://stackoverflow.com/questions/29986657/global-variable-usage-on-page-reload/ – guest271314 Jun 26 '16 at 05:22

0 Answers0