Forked from shaik2many/javascript-localstorage-expiry.js
Created
March 4, 2018 01:26
-
-
Save jonabaptistella/ce386e1f5b049259210b2009556642bc to your computer and use it in GitHub Desktop.
set timeout for localStorage or sessionStorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http://apassant.net/2012/01/16/timeout-for-html5-localstorage/ | |
| var hours = 24; // Reset when storage is more than 24hours | |
| var now = new Date().getTime(); | |
| var setupTime = localStorage.getItem('setupTime'); | |
| if (setupTime == null) { | |
| localStorage.setItem('setupTime', now) | |
| } else { | |
| if(now-setupTime > hours*60*60*1000) { | |
| localStorage.clear() | |
| localStorage.setItem('setupTime', now); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment