storage-file-url.html (1596B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <title>Storage Test</title> 6 <script> 7 "use strict"; 8 /* exported setup */ 9 function setup() { 10 createIndexedDB(); 11 createCookies(); 12 createLocalStorage(); 13 createSessionStorage(); 14 } 15 16 function createIndexedDB() { 17 const open = indexedDB.open("MyDatabase", 1); 18 19 open.onupgradeneeded = function () { 20 const db = open.result; 21 db.createObjectStore("MyObjectStore", {keyPath: "id"}); 22 }; 23 24 open.onsuccess = function () { 25 const db = open.result; 26 const tx = db.transaction("MyObjectStore", "readwrite"); 27 const store = tx.objectStore("MyObjectStore"); 28 29 store.put({id: 12345, name: {first: "John", last: "Doe"}, age: 42}); 30 store.put({id: 54321, name: {first: "Ralph", last: "Wood"}, age: 38}); 31 store.put({id: 67890, name: {first: "Bob", last: "Smith"}, age: 35}); 32 store.put({id: 98765, name: {first: "Freddie", last: "Krueger"}, age: 40}); 33 34 tx.oncomplete = function () { 35 db.close(); 36 }; 37 }; 38 } 39 40 function createCookies() { 41 document.cookie = "test1=Jean Dupond"; 42 document.cookie = "test2=dnopuD naeJ"; 43 } 44 45 function createLocalStorage() { 46 localStorage.setItem("test3", "John Doe"); 47 localStorage.setItem("test4", "eoD nhoJ"); 48 } 49 50 function createSessionStorage() { 51 sessionStorage.setItem("test5", "John Smith"); 52 sessionStorage.setItem("test6", "htimS nhoJ"); 53 } 54 </script> 55 </head> 56 <body> 57 <h1>IndexedDB Test</h1> 58 </body> 59 </html>