From dfd5c8b4ecee8f926dc6f525f1685e80cb8219b1 Mon Sep 17 00:00:00 2001 From: Stian Lund Date: Fri, 14 Jul 2023 17:07:55 +0200 Subject: [PATCH] add session storage test --- test/index.html | 5 ++-- test/session-storage/index.html | 39 ++++++++++++++++++++++++++++ test/session-storage/storage-test.js | 23 ++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100755 test/session-storage/index.html create mode 100755 test/session-storage/storage-test.js diff --git a/test/index.html b/test/index.html index af7ad58..1933cff 100644 --- a/test/index.html +++ b/test/index.html @@ -30,7 +30,7 @@

test

..
[   0 Oct  7  2022]  cache
-[   0 Jul  5 18:14]  favicon-cors
+[   0 Jul 14 17:06]  favicon-cors
[   0 Jul  5 17:58]  favicon-svg
[   0 Feb 17  0:37]  float
[   0 Jul  9  2022]  focus
@@ -40,6 +40,7 @@ [   0 Dec 30  2022]  media-fullscreen
[   0 Jul  9  2022]  pdf
[   0 Jul  9  2022]  referrer
+[   0 Jul 14 16:52]  session-storage
[   0 Jul  9  2022]  translate
[   0 Oct  7  2022]  video-mkv-aac
[   0 May  6 20:37]  window-open-crash
@@ -48,7 +49,7 @@

-14 directories, 1 file +15 directories, 1 file

diff --git a/test/session-storage/index.html b/test/session-storage/index.html new file mode 100755 index 0000000..3703a30 --- /dev/null +++ b/test/session-storage/index.html @@ -0,0 +1,39 @@ + + + + Test of HTML5 localStorage and sessionStorage persistence + + + +

Test of HTML5 localStorage and sessionStorage persistence

+ +

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.

+

Then click the button to open a popup window.

+ +

+ Local storage:
+ + +

+ +

+ Session storage:
+ + +

+ +

+

+ + + + + + + + + \ No newline at end of file diff --git a/test/session-storage/storage-test.js b/test/session-storage/storage-test.js new file mode 100755 index 0000000..31e13ee --- /dev/null +++ b/test/session-storage/storage-test.js @@ -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";