leaving_page_iframe.html (1012B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script> 5 var db; 6 function startDBWork() { 7 indexedDB.open(parent.location, 1).onupgradeneeded = function(e) { 8 db = e.target.result; 9 if (db.objectStoreNames.contains("mystore")) { 10 db.deleteObjectStore("mystore"); 11 } 12 var store = db.createObjectStore("mystore"); 13 store.add({ hello: "world" }, 42); 14 e.target.onsuccess = madeMod; 15 }; 16 } 17 18 function madeMod() { 19 var trans = db.transaction(["mystore"], "readwrite"); 20 var store = trans. 21 objectStore("mystore"); 22 trans.oncomplete = function() { 23 parent.postMessage("didcommit", "*"); 24 }; 25 26 store.put({ hello: "officer" }, 42).onsuccess = function() { 27 // Make this transaction run until the end of time or until the page is 28 // navigated away, whichever comes first. 29 function doGet() { 30 store.get(42).onsuccess = doGet; 31 } 32 doGet(); 33 document.location = "about:blank"; 34 }; 35 } 36 </script> 37 </head> 38 <body onload="startDBWork();"> 39 This is page one. 40 </body> 41 </html>