简体   繁体   English

保存当前页面状态javascript

[英]Save current page state javascript

Is it possible to save the current state of a webpage so you can later restore it to that state? 是否可以保存网页的当前状态,以便以后可以将其恢复到该状态?

Through "state" I mean everything that defines the current behavior of the page: html tags, css, JavaScript variables, form data, etc... 通过“状态”,我指的是定义页面当前行为的所有内容:html标签,css,JavaScript变量,表单数据等......

So you could simply have something like: savePage() which stores all the needed data in localhost and then use loadPage() to retrieve that data. 所以你可以简单地使用: savePage()将所有需要的数据存储在localhost中,然后使用loadPage()来检索该数据。

I guess the html , css and inputs value are easy to save, but what about all the JavaScript variables on that page? 我想htmlcssinputs value很容易保存,但那个页面上的所有JavaScript变量呢? Is it possible to save all the JavaScript variables held in the memory? 是否可以保存内存中保存的所有JavaScript变量? (probably in a JSON object). (可能在JSON对象中)。

Essentially what you want is to resuse something when user comes back,so here is my answer. 基本上你想要的是在用户回来时重新使用某些东西,所以这是我的答案。

well its certainly possible.You can traverse the dom and put your stuff in to localstorage. 这当然是可能的。你可以穿过dom并把你的东西放到本地存储中。

LocalStorage supports only string. LocalStorage仅支持字符串。

Use localStorage if you want the data to persist beyond browser close and SessionStorage if i want the data to persist with in the browser close. 如果您希望数据在浏览器关闭和SessionStorage之后保持不变,如果我希望数据在浏览器中保持关闭,请使用localStorage。

NOTE :IE7 + support for SessionStorage and LocalStorage 注意 :IE7 +支持SessionStorage和LocalStorage

It has plenty of memory as compared to cookies(4kb with 15 to 20 cookies allowed per domain). 与cookie相比,它有足够的内存(4kb,每个域允许15到20个cookie)。

  • IE(10 mb) IE(10 mb)
  • Mozzilla(5 mb) Mozzilla(5 mb)
  • Chrome(2.5 mb) 铬(2.5 MB)

Well depends, you can use localStorage to do that on the client side, or for example write a javascript function to send all variables to the server and store them there. 嗯,您可以使用localStorage在客户端执行此操作,或者例如编写一个javascript函数将所有变量发送到服务器并将其存储在那里。

You need to think more about that problem. 你需要更多地思考这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM