Chrome の Javascript コンソールからも中身を確認することができる
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8"/>
<title>Web Storage</title>
</head>
<body>
<button onclick="removeItem('skey1')">remove1</button>
<button onclick="removeItem('skey2')">remove2</button>
<button onclick="clearItem()">clear3-4</button>
<button onclick="setItem('lkey5')">add5</button>
<br/>
<textarea id='dumpTextArea1' cols="40" rows="5"></textarea>
<textarea id='dumpTextArea2' cols="40" rows="5"></textarea>
<script type="text/javascript">
(function(){
if (typeof(Storage) === 'undefined') {
alert('web storage is not supported');
return;
}
var sstorage = sessionStorage;
sstorage.setItem('skey1', 'svalue1');
sstorage.setItem('skey2', 'svalue2');
var lstorage = localStorage;
lstorage.setItem('lkey3', 'lvalue3');
lstorage.setItem('lkey4', 'lvalue4');
dumpStorage();
})();
function removeItem(key) {
sessionStorage.removeItem(key);
dumpStorage();
}
function setItem(key) {
localStorage.setItem(key,'newValue');
dumpStorage();
}
function clearItem() {
localStorage.clear();
dumpStorage();
}
function dumpStorage() {
var ss = sessionStorage;
var ls = localStorage;
var dump = '';
for (var cnt = 0; cnt < ss.length; cnt++) {
var key = ss.key(cnt)
dump += (key + ' = ' + ss.getItem(key) + '\n');
}
document.getElementById('dumpTextArea1').value = dump;
dump = '';
for (var cnt = 0; cnt < ls.length; cnt++) {
var key = ls.key(cnt)
dump += (key + ' = ' + ls.getItem(key) + '\n');
}
document.getElementById('dumpTextArea2').value = dump;
}
</script>
</body>
</html>