1
0
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:
Stian Lund
2023-07-14 17:07:55 +02:00
parent d0f9cb2e61
commit dfd5c8b4ec
3 changed files with 65 additions and 2 deletions

View File

@@ -30,7 +30,7 @@
<h1>test</h1><p>
<a class="NORM" href="..">..</a><br>
[&nbsp;&nbsp;&nbsp;0&nbsp;Oct&nbsp;&nbsp;7&nbsp;&nbsp;2022]&nbsp;&nbsp;<a class="DIR" href="./cache/">cache</a><br>
[&nbsp;&nbsp;&nbsp;0&nbsp;Jul&nbsp;&nbsp;5&nbsp;18:14]&nbsp;&nbsp;<a class="DIR" href="./favicon-cors/">favicon-cors</a><br>
[&nbsp;&nbsp;&nbsp;0&nbsp;Jul&nbsp;14&nbsp;17:06]&nbsp;&nbsp;<a class="DIR" href="./favicon-cors/">favicon-cors</a><br>
[&nbsp;&nbsp;&nbsp;0&nbsp;Jul&nbsp;&nbsp;5&nbsp;17:58]&nbsp;&nbsp;<a class="DIR" href="./favicon-svg/">favicon-svg</a><br>
[&nbsp;&nbsp;&nbsp;0&nbsp;Feb&nbsp;17&nbsp;&nbsp;0:37]&nbsp;&nbsp;<a class="DIR" href="./float/">float</a><br>
[&nbsp;&nbsp;&nbsp;0&nbsp;Jul&nbsp;&nbsp;9&nbsp;&nbsp;2022]&nbsp;&nbsp;<a class="DIR" href="./focus/">focus</a><br>
@@ -40,6 +40,7 @@
[&nbsp;&nbsp;&nbsp;0&nbsp;Dec&nbsp;30&nbsp;&nbsp;2022]&nbsp;&nbsp;<a class="DIR" href="./media-fullscreen/">media-fullscreen</a><br>
[&nbsp;&nbsp;&nbsp;0&nbsp;Jul&nbsp;&nbsp;9&nbsp;&nbsp;2022]&nbsp;&nbsp;<a class="DIR" href="./pdf/">pdf</a><br>
[&nbsp;&nbsp;&nbsp;0&nbsp;Jul&nbsp;&nbsp;9&nbsp;&nbsp;2022]&nbsp;&nbsp;<a class="DIR" href="./referrer/">referrer</a><br>
[&nbsp;&nbsp;&nbsp;0&nbsp;Jul&nbsp;14&nbsp;16:52]&nbsp;&nbsp;<a class="DIR" href="./session-storage/">session-storage</a><br>
[&nbsp;&nbsp;&nbsp;0&nbsp;Jul&nbsp;&nbsp;9&nbsp;&nbsp;2022]&nbsp;&nbsp;<a class="DIR" href="./translate/">translate</a><br>
[&nbsp;&nbsp;&nbsp;0&nbsp;Oct&nbsp;&nbsp;7&nbsp;&nbsp;2022]&nbsp;&nbsp;<a class="DIR" href="./video-mkv-aac/">video-mkv-aac</a><br>
[&nbsp;&nbsp;&nbsp;0&nbsp;May&nbsp;&nbsp;6&nbsp;20:37]&nbsp;&nbsp;<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
View 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>

View 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";