Last active
December 14, 2015 06:18
-
-
Save tleite/5041133 to your computer and use it in GitHub Desktop.
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
// if localStorage is present, use that | |
if (('localStorage' in window) && window.localStorage !== null) { | |
// easy object property API | |
localStorage.wishlist = '["Unicorn","Narwhal","Deathbear"]'; | |
} else { | |
// without sessionStorage we'll have to use a far-future cookie | |
// with document.cookie's awkward API :( | |
var date = new Date(); | |
date.setTime(date.getTime()+(365*24*60*60*1000)); | |
var expires = date.toGMTString(); | |
var cookiestr = 'wishlist=["Unicorn","Narwhal","Deathbear"];'+ | |
' expires='+expires+'; path=/'; | |
document.cookie = cookiestr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment