I am building a form in which i have to store the data in html5's sessionStorage
i don't know where the sessionStorage
expires. Can anyone tell me about the expiration time of the sessionStorage
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
I know this question is pretty old but I will post my answer if someone else stumbles upon this and finds it helpful. You can pretty much simulate
sessionStorage
orlocaStorage
expiration with something like this:You can also encrypt this object by using something like http://bitwiseshiftleft.github.io/sjcl/ if you don't want this session object to be in clear.
On every page load you can check if the
sessionStorage
, orlocalStorage
for that matter, is expired:If you do not want users to be kept as logged in after the tab or browser closes use
sessionStorage
, otherwise you should uselocalStorage
and manipulate it as you desire.I hope someone will find this helpful.
You can save expiration time in cookie. In every page loading read the cookie, if it's empty (means expired) then clear sessionstorage.
It lives and dies with your browser session and is not shared between tabs. It doesn't expire automatically. So if you never close your browser it never expires.
So when the tab/window is closed the data is lost.
Each sessionstorage area is allowed 5mb of storage (in some browsers 10mb). Where as cookies only allow 4kb (or more in some browsers). Cookies however has a set expiration date.
As Christophe wrote in the comments, localstorage never expires. It's also shared across tabs and is the same size as sessionstorage (5mb).
You can add some kind of expiration mechanism with something like this :