保存当前页面状态的JavaScript [英] Save current page state javascript

查看:672
本文介绍了保存当前页面状态的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能保存网页的当前状态,以便以后可以将其恢复到该状态?通过状态,我的意思是定义当前状态页面的行为:html标记,css,JavaScript变量,表单数据等...

所以你可以简单地使用类似于: savePage (),它将所有需要的数据存储在localhost中,然后使用 loadPage()来检索该数据。



我猜测 html css 输入值很容易保存,但那个页面上的所有JavaScript变量呢?是否可以保存内存中保存的所有JavaScript变量? (可能位于 JSON 对象中)。

解决方案

当用户回来的时候会重新使用某些东西,所以这里是我的答案。

当然可以。你可以遍历这个dom并把你的东西放到本地存储中。

p>

LocalStorage仅支持字符串。

如果您希望数据在浏览器关闭之后持续存在,并且SessionStorage存在在浏览器中保留的数据关闭。


$ b

注意:对SessionStorage和LocalStorage的IE7 +支持

与cookie相比,它拥有充足的内存(每个域允许4到15到20个cookie)。


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

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...

So you could simply have something like: savePage() which stores all the needed data in localhost and then use loadPage() to retrieve that data.

I guess the html, css and inputs value are easy to save, but what about all the JavaScript variables on that page? Is it possible to save all the JavaScript variables held in the memory? (probably in a JSON object).

解决方案

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.

LocalStorage supports only string.

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.

NOTE:IE7 + support for SessionStorage and LocalStorage

It has plenty of memory as compared to cookies(4kb with 15 to 20 cookies allowed per domain).

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

这篇关于保存当前页面状态的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆