最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Can JavaScript maintain any state after a reload? - Stack Overflow

programmeradmin5浏览0评论

Is there a way to have JavaScript hold any variables through a reload?

If the user hits the reload button, is there any state that is kept by JavaScript, once a page is reloaded?

Is there a way to have JavaScript hold any variables through a reload?

If the user hits the reload button, is there any state that is kept by JavaScript, once a page is reloaded?

Share edited May 29, 2012 at 23:22 Charles 51.4k13 gold badges106 silver badges144 bronze badges asked May 29, 2012 at 22:49 user656925user656925 3
  • 1 This is now the third time I've had to correct your spelling of javascript in the past few days. Please take more care when selecting tags! – Charles Commented May 29, 2012 at 23:22
  • Indeed, you gained the ability to create new tags once you hit 1500 reputation. – Charles Commented May 30, 2012 at 17:04
  • Possible duplicate of Global Variable usage on page reload – Liam Commented Jun 1, 2017 at 14:52
Add a ment  | 

3 Answers 3

Reset to default 5

Suggestions

  • Cookie
  • HTML 5 Web Storage https://www.w3schools./html/html5_webstorage.asp

Either way, you'll need to write your own read/write methods to store your state.

You will have to utilize cookies to maintain your state. If you're using jQuery I sugest you look into jQuery Cookie:

https://github./carhartl/jquery-cookie

Hope this helps you!

small data (2KByte) can be stored in the URL suffix

fragment ID: //host/path#fragment-id

query string: //host/path?query-string

the fragment-id-method is used here:
http://xkcd-map.rent-a-geek.de/
on every dragend-event, the URL is changed
to reflect the current position on the map

special chars mut be urlencode-d

related: hot reloading, reloadable code, figwheel.clj, react.js hot loader

发布评论

评论列表(0)

  1. 暂无评论