leaving_page_iframe.html 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. var trans = e.target.transaction;
  10. if (db.objectStoreNames.contains("mystore")) {
  11. db.deleteObjectStore("mystore");
  12. }
  13. var store = db.createObjectStore("mystore");
  14. store.add({ hello: "world" }, 42);
  15. e.target.onsuccess = madeMod;
  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. store.put({ hello: "officer" }, 42).onsuccess = function(e) {
  26. // Make this transaction run until the end of time or until the page is
  27. // navigated away, whichever comes first.
  28. function doGet() {
  29. store.get(42).onsuccess = doGet;
  30. }
  31. doGet();
  32. document.location = "about:blank";
  33. }
  34. }
  35. </script>
  36. </head>
  37. <body onload="startDBWork();">
  38. This is page one.
  39. </body>
  40. </html>