Local storage save and retrieve
This file contains 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
function SaveYourName() { | |
var yourName = $("#yourName").val(); | |
if (Modernizr.localstorage) { | |
try { | |
//saves to the database, “key”, “value” | |
localStorage.setItem("name", yourName); | |
} catch (e) { | |
if (e == QUOTA_EXCEEDED_ERR) { | |
//data wasn’t successfully saved due to quota exceed so throw an error | |
alert('Quota exceeded!'); | |
} | |
} | |
$("#yoursavedname").append("Your name was saved:" + localStorage.getItem("name")); | |
} | |
else { | |
var exdate = new Date(); | |
exdate.setDate(exdate.getDate() + 30); | |
var c_value = escape($(yourName).val()) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString()); | |
document.cookie = c_name + "=" + c_value; | |
$("#yoursavedname").append("Your cookie:" + document.cookie); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment