Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...