-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_webstorage.html
More file actions
55 lines (53 loc) · 1.5 KB
/
04_webstorage.html
File metadata and controls
55 lines (53 loc) · 1.5 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html>
<head>
<meta charset="euc-kr" />
<meta name="viewport"
content="width=device-width, initial-scale=1.0,
maximum-scale=1.0, minimum-scale=1.0,
user-scalable=no"/>
<title>HTML5</title>
<script type="text/javascript">
function saveLocalStorage() {
if(window.localStorage) {
var text1 = document.querySelector("#text1");
window.localStorage.setItem("text1", text1.value);
}
}
function readLocalStorage() {
if(window.localStorage) {
var value = window.localStorage.getItem("text1");
var span1 = document.querySelector("#span1");
span1.innerHTML = value;
}
}
function saveSessionStorage() {
if(window.sessionStorage) {
var text2 = document.querySelector("#text2");
window.sessionStorage.setItem("text2", text2.value);
}
}
function readSessionStorage() {
if(window.sessionStorage) {
var value = window.sessionStorage.getItem("text2");
var span2 = document.querySelector("#span2");
span2.innerHTML = value;
}
}
</script>
</head>
<body>
<h3>Local Storage</h3>
<button onclick="saveLocalStorage()">ÀúÀå</button>
<input id="text1" type="text"/>
<br/>
<button onclick="readLocalStorage()">Á¶È¸</button>
<span id="span1"></span><br/>
<h3>Session Storage</h3>
<button onclick="saveSessionStorage()">ÀúÀå</button>
<input id="text2" type="text"/>
<br/>
<button onclick="readSessionStorage()">Á¶È¸</button>
<span id="span2"></span><br/>
</body>
</html>