Forked from dimitrikennedy/javascript:localstorage.cookie.js
Created
October 1, 2012 08:10
Revisions
-
netsi1964 revised this gist
Oct 1, 2012 . 1 changed file with 8 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -39,13 +39,13 @@ if (!window.localStorage) { } function getStored(sKey, sDefault) { var val = localStorage.getItem(sKey); if (typeof sDefault!=='undefined' && val===null) { val = sDefault; localStorage.setItem(sKey, val); } return val; } alert(getStored('test', 111)); -
netsi1964 revised this gist
Oct 1, 2012 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -38,3 +38,14 @@ if (!window.localStorage) { })(); } function getStored(sKey, sDefault) { var val = localStorage.getItem(sKey); if (typeof sDefault!=='undefined' && val===null) { val = sDefault; localStorage.setItem(sKey, val); } return val; } alert(getStored('test', 111)); -
dimitrikennedy revised this gist
Mar 9, 2012 . 1 changed file with 40 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ var createCookie, readCookie; if (!window.localStorage) { createCookie = function(name, value, days) { var date, expires = ""; if (days) { date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } document.cookie = name + "=" + value + expires + "; path=/"; }; readCookie = function(name) { var result = "", nameEQ = name + "=", ca = document.cookie.split(';'), i, c; for (i = 0; i < ca.length; i++) { c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1, c.length); } result = c.indexOf(nameEQ) === 0 ? c.substring(nameEQ.length, c.length) : ""; } return (result); }; localStorage = (function() { return { setItem: function(key, value) { createCookie(key, value, 3000); }, getItem: function(key) { return (readCookie(key)); } }; })(); } -
devfred created this gist
Mar 9, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ var createCookie, readCookie; if (!window.localStorage) { createCookie = function(name, value, days) { var date, expires = ""; if (days) { date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } document.cookie = name + "=" + value + expires + "; path=/"; }; readCookie = function(name) { var result = "", nameEQ = name + "=", ca = document.cookie.split(';'), i, c; for (i = 0; i < ca.length; i++) { c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1, c.length); } result = c.indexOf(nameEQ) === 0 ? c.substring(nameEQ.length, c.length) : ""; } return (result); }; localStorage = (function() { return { setItem: function(key, value) { createCookie(key, value, 3000); }, getItem: function(key) { return (readCookie(key)); } }; })(); }