Save current javascript page state

Can I save the current state of a web page so that I can later restore it to this state?

Through "state" I mean everything that determines the current behavior of the page: html, css tags, JavaScript variables, form data, etc.

That way you can just have something like: savePage() , which stores all the necessary data in localhost, and then use loadPage() to retrieve that data.

I think html , css and inputs value easy to save, but what about all the JavaScript variables on this page? Is it possible to save all JavaScript variables stored in memory? (possibly in a JSON object).

+4
source share
2 answers

Essentially, you want to try something when the user returns, so here is my answer.

Well, certainly it is possible. You can cross the house and put your stuff in localstorage.

LocalStorage only supports string.

Use localStorage if you want the data to be stored outside of the browser close and SessionStorage if I want the data to be saved in a closed browser.

NOTE : IE7 + support for SessionStorage and LocalStorage

It has a lot of memory compared to cookies (4kb with a permitted number of files from 15 to 20 for each domain).

  • IE (10 mb)
  • Mozzilla (5 mb)
  • Chrome (2.5 mb)
+1
source

Well, you can use localStorage for this on the client side or, for example, write a javascript function to send all the variables to the servers and save them there.

You need to think more about this problem.

0
source

Source: https://habr.com/ru/post/1499940/


All Articles