Local Storage - Serialization 💾
Local Storage - Serialization
Full code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!--Unicode Transformation Format – 8-bit-->
<title>Local Storage - Serialization</title>
</head>
<!--code by Serge Seveau August 2023-->
<body>
<h1>Local Storage - Serialization</h1>
<form id="frmWelcome">
<fieldset> <!--creates a rectangular box-->
<span id="spnMessage"></span><br/>
<br><br><br><br>
</fieldset>
</form>
<br><br>
<input type="button" value="save" onclick="save()"/>
<input type="button" value="revert" onclick="revert()"/>
<input type="button" value="unSave" onclick="unSave()"/>
<script type="text/javascript">
let meStuff = {
name: "Serge",
age: 60,
height: 172
};
let meStuff_serialized = JSON.stringify(meStuff);
function save()
{
localStorage.setItem("meStuff", meStuff_serialized);
spnMessage.innerHTML = meStuff_serialized;
console.log(meStuff_serialized)
}
function revert()
{
let meStuff_deserialized = JSON.parse(localStorage.getItem("meStuff"));
spnMessage.innerHTML = meStuff_deserialized;
console.log(meStuff_deserialized)
}
function unSave()
{
localStorage.clear();
spnMessage.innerHTML = localStorage;
console.log(localStorage)
}
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="utf-8">
<!--Unicode Transformation Format – 8-bit-->
<title>Local Storage - Serialization</title>
</head>
<!--code by Serge Seveau August 2023-->
<body>
<h1>Local Storage - Serialization</h1>
<form id="frmWelcome">
<fieldset> <!--creates a rectangular box-->
<span id="spnMessage"></span><br/>
<br><br><br><br>
</fieldset>
</form>
<br><br>
<input type="button" value="save" onclick="save()"/>
<input type="button" value="revert" onclick="revert()"/>
<input type="button" value="unSave" onclick="unSave()"/>
<script type="text/javascript">
let meStuff = {
name: "Serge",
age: 60,
height: 172
};
let meStuff_serialized = JSON.stringify(meStuff);
function save()
{
localStorage.setItem("meStuff", meStuff_serialized);
spnMessage.innerHTML = meStuff_serialized;
console.log(meStuff_serialized)
}
function revert()
{
let meStuff_deserialized = JSON.parse(localStorage.getItem("meStuff"));
spnMessage.innerHTML = meStuff_deserialized;
console.log(meStuff_deserialized)
}
function unSave()
{
localStorage.clear();
spnMessage.innerHTML = localStorage;
console.log(localStorage)
}
</script>
</body>
</html>