mirror of
https://github.com/Pathduck/pathduck.github.io.git
synced 2025-12-29 11:45:20 -05:00
add session storage test
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
<h1>test</h1><p>
|
||||
<a class="NORM" href="..">..</a><br>
|
||||
[ 0 Oct 7 2022] <a class="DIR" href="./cache/">cache</a><br>
|
||||
[ 0 Jul 5 18:14] <a class="DIR" href="./favicon-cors/">favicon-cors</a><br>
|
||||
[ 0 Jul 14 17:06] <a class="DIR" href="./favicon-cors/">favicon-cors</a><br>
|
||||
[ 0 Jul 5 17:58] <a class="DIR" href="./favicon-svg/">favicon-svg</a><br>
|
||||
[ 0 Feb 17 0:37] <a class="DIR" href="./float/">float</a><br>
|
||||
[ 0 Jul 9 2022] <a class="DIR" href="./focus/">focus</a><br>
|
||||
@@ -40,6 +40,7 @@
|
||||
[ 0 Dec 30 2022] <a class="DIR" href="./media-fullscreen/">media-fullscreen</a><br>
|
||||
[ 0 Jul 9 2022] <a class="DIR" href="./pdf/">pdf</a><br>
|
||||
[ 0 Jul 9 2022] <a class="DIR" href="./referrer/">referrer</a><br>
|
||||
[ 0 Jul 14 16:52] <a class="DIR" href="./session-storage/">session-storage</a><br>
|
||||
[ 0 Jul 9 2022] <a class="DIR" href="./translate/">translate</a><br>
|
||||
[ 0 Oct 7 2022] <a class="DIR" href="./video-mkv-aac/">video-mkv-aac</a><br>
|
||||
[ 0 May 6 20:37] <a class="DIR" href="./window-open-crash/">window-open-crash</a><br>
|
||||
@@ -48,7 +49,7 @@
|
||||
</p>
|
||||
<p>
|
||||
|
||||
14 directories, 1 file
|
||||
15 directories, 1 file
|
||||
<br><br>
|
||||
</p>
|
||||
</html>
|
||||
|
||||
39
test/session-storage/index.html
Executable file
39
test/session-storage/index.html
Executable file
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test of HTML5 localStorage and sessionStorage persistence</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h2>Test of HTML5 localStorage and sessionStorage persistence</h2>
|
||||
|
||||
<p>Enter data in either box and click the button to store it. If you navigate to this page in a new window or tab, or quit and relaunch your browser, localStorage will remain and sessionStorage will disappear.</p>
|
||||
<p>Then click the button to open a popup window.</p>
|
||||
|
||||
<p>
|
||||
Local storage:<br />
|
||||
<input type="text" placeholder="nothing currently stored" size="30" id="local" />
|
||||
<input type="button" onclick="store_it('local', window.localStorage);" value="Store it" />
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Session storage:<br />
|
||||
<input type="text" placeholder="nothing currently stored" size="30" id="session" />
|
||||
<input type="button" onclick="store_it('session', window.sessionStorage);" value="Store it" />
|
||||
</p>
|
||||
|
||||
<p id="local-warning"></p>
|
||||
<p id="session-warning"></p>
|
||||
|
||||
<script type="text/javascript" src="storage-test.js"></script>
|
||||
|
||||
<button onclick="myFunction()">Open Popup</button>
|
||||
|
||||
<script>
|
||||
function myFunction() {
|
||||
window.open("index.html", "_blank", "width=600, height=500");
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
23
test/session-storage/storage-test.js
Executable file
23
test/session-storage/storage-test.js
Executable file
@@ -0,0 +1,23 @@
|
||||
function store_it(id, storageArea) {
|
||||
var textBox = document.getElementById(id);
|
||||
if (!textBox.value)
|
||||
delete storageArea.theirValue; // don't store empty string, delete it instead
|
||||
else
|
||||
storageArea.theirValue = textBox.value;
|
||||
}
|
||||
|
||||
function retrieve_storage(id, storageArea) {
|
||||
var val = storageArea.theirValue;
|
||||
if (val != null)
|
||||
document.getElementById(id).value = val;
|
||||
}
|
||||
|
||||
if (window.localStorage)
|
||||
retrieve_storage("local", localStorage);
|
||||
else
|
||||
document.getElementById("local-warning").innerHTML = "Note: this browser does not support localStorage";
|
||||
|
||||
if (window.sessionStorage)
|
||||
retrieve_storage("session", sessionStorage);
|
||||
else
|
||||
document.getElementById("session-warning").innerHTML = "Note: this browser does not support sessionStorage";
|
||||
Reference in New Issue
Block a user