-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexample 4.html
More file actions
39 lines (28 loc) · 914 Bytes
/
Copy pathexample 4.html
File metadata and controls
39 lines (28 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1 id="header1">Big Title</h1>
<button onclick="changeHeader()">Click to change title</button>
<script>
personOriginalObject = {
name: "John",
age: function() {
return 31;
},
city: "New York"
}
personOriginalObject.age = personOriginalObject.age.toString();
personJson = JSON.stringify(personOriginalObject);
localStorage.setItem("person1", personJson);
person = localStorage.getItem("person1");
personObject = JSON.parse(person);
personObject.age = eval("(" + personObject.age + ")");
function changeHeader() {
document.getElementById("header1").innerHTML = personObject.name + " " + personObject.age() + " " + personObject.city;
}
</script>
</body>
</html>