html
html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Testing LocalStorage</title>
</head>
<body>
<script type="text/javascript">
window.onload = function(){
//localStorage API
//check whether item is already saved or not before doing anything
if(!localStorage.getItem('name')){
//if not done before then store the data in browser permanently
localStorage.setItem('name', 'Morpheus');
alert('Morpheus saved in browser permanently with localStorage API');
} else {
/*Next time when you open the browser the alert wont pop up, because
the name Moepheus already exists in your browser */
var userName = localStorage.getItem('name');
document.body.innerHTML = userName + " already exists so not showing alert!";
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
body {
}
Enter to Rename, Shift+Enter to Preview
js
js
1
alert("local storage will come handy for persistence storage , but must be tested on regular browser, coz file access not supported on SoloLearn");
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run