Skip to content

Instantly share code, notes, and snippets.

@mkhuda
Created May 3, 2013 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkhuda/c182063f3278d48051a3 to your computer and use it in GitHub Desktop.
Save mkhuda/c182063f3278d48051a3 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Percobaan HTML5 Local Storage</title>
<script type="text/javascript" charset="utf-8" src="jquery.js"></script>
<script type="text/javascript" >
// fungsi simpan(), ketika tombol diklik maka string
// di dalam input akan tersimpan ke dalam storage browser
function simpan() {
var storage = document.getElementById('nama').value;
localStorage.setItem('Text',storage);
}
// tampil() akan menampilkan string yang tersimpan
// ke tag div yang ditentukan "hasil"
function tampil() {
var tampilNama = localStorage.getItem('Text');
if (tampilNama) {
x = document.getElementById('tampil');
x.innerHTML=tampilNama;
}
}
// fungsi untuk menghapus localstorage browser
function hapus() {
localStorage.removeItem('Text');
}
</script>
</head>
<body>
<input type="text" id="nama" />
<input type="button" value="Simpan" onclick="simpan()" />
<input type="button" value="Tampil" onclick="tampil()" />
<input type="button" value="Hapus" onclick="hapus()" />
<div id="tampil"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment