Skip to content

Commit

Permalink
mdn: using-the-web-storage-api
Browse files Browse the repository at this point in the history
  • Loading branch information
kesava-karri committed Apr 5, 2024
1 parent 6c59ffc commit d2060c4
Show file tree
Hide file tree
Showing 14 changed files with 1,303 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width" />

<title>Web Storage API storage event output</title>

<link rel="stylesheet" href="style.css" />
</head>

<body>
<div class="wrapper">
<h1>Event output</h1>

<ul>
<li>Key: <span class="my-key"></span></li>
<li>Old value: <span class="my-old"></span></li>
<li>New value: <span class="my-new"></span></li>
<li>URL: <span class="my-url"></span></li>
<li>Storage area: <span class="my-storage"></span></li>
</ul>

<p>Go back to the <a href="index.html">main example page</a>.</p>
</div>
<script src="event.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
window.addEventListener('storage', function(e) {
document.querySelector('.my-key').textContent = e.key;
document.querySelector('.my-old').textContent = e.oldValue;
document.querySelector('.my-new').textContent = e.newValue;
document.querySelector('.my-url').textContent = e.url;
document.querySelector('.my-storage').textContent = JSON.stringify(e.storageArea);
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width" />

<title>Web Storage API example</title>

<link rel="stylesheet" href="style.css" />
</head>

<body>
<div class="wrapper">
<h1>Web storage</h1>

<p>
This example is designed to demonstrate usage of the
<a
href="https://html.spec.whatwg.org/multipage/webstorage.html#webstorage"
>W3C Web Storage API</a
>. It should work as far back as IE8. Choose custom background colours,
logos and fonts from the below drop down menus, then try closing and
reopening the page — you will find that your choices are remembered, as
they are stored using Web Storage. You can also visit the
<a href="event.html" target="_blank">storage event output</a> (opens in
new tab). Open this, change some values in the index page, then look at
the events page — you'll see the storage changes reported.
</p>

<form>
<div>
<label for="bgcolor">Choose background color:</label>
<input class="color" id="bgcolor" value="FF0000" />
</div>
<div>
<label for="font">Choose font style:</label>
<select id="font">
<option value="sans-serif" selected>Sans-serif</option>
<option value="serif">Serif</option>
<option value="monospace">Monospace</option>
</select>
</div>
<div>
<label for="image">Choose image:</label>
<select id="image">
<option value="images/firefoxos.png" selected>Firefox</option>
<option value="images/crocodile.png">Crocodile</option>
<option value="images/tortoise.png">Tortoise</option>
</select>
</div>
</form>

<footer></footer>
<img src="images/firefoxos.png" />
</div>

<script src="jscolor/jscolor.js"></script>
<script src="main.js"></script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>jscolor demo</title>
</head>
<body>

<script type="text/javascript" src="jscolor.js"></script>

Click here: <input class="color" value="66ff00">

</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d2060c4

Please sign in to comment.