cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <h3>Demonstrating basic IndexedDB specification conformance (and failures in IE 10+11)</h3>

<p><small><a href="https://github.com/Fyrd/caniuse/pull/532">more info</a></small></p>

<div id="log"></div>
            
          
!
            
              var log = function (msg, style) {
  document.getElementById("log").innerHTML += "<div style='" + style + "'>" + msg + "</div>";
};
var elog = function (msg) {
  log(msg, "font-weight:bold; color:red");
};

log("Running on: " + navigator.userAgent);

indexedDB.deleteDatabase("xxx");

var req = indexedDB.open("xxx");
req.onerror = function (e) {
  log("failed to open database, look in console log");
  console.log(e);
};
req.onupgradeneeded = function () {
  var db = req.result;
  try {
    var store = db.createObjectStore("array-keypath", {keyPath: ["a", "c"]});
    store.put({a:6, b:6, c:7});
    log("This browser supports using array `keyPath`s.")
  } catch (e) {
    elog("This browser does not support using array `keyPath`s: " + e.message);
  }
  
  try {
    var dk_store = db.createObjectStore("dotted-keypath", {keyPath: "a.b"});
    dk_store.put({a:{b:7}}).onsuccess = function (e) {
      log("This browser supports storing objects using dotted `keyPath`s.");
      var areq = dk_store.get(7);
      areq.onsuccess = function (e) {
        if (_.isEqual(e.target.result, {a:{b:7}})) {
          log("This browser supports retrieving objects stored using dotted `keyPath`s.");
        } else {
          elog("This browser does not support retriving objects stored using dotted `keyPath`s.");
        }
      }; 
      areq.onerror = function (e) {
        elog("This browser does not support retriving objects stored using dotted `keyPath`s.");
      };
    };
  } catch (e) {
    elog("This browser does not support using dotted `keyPath`s: " + e.message);
  }
  
  try {
    var store = db.createObjectStore("array-key");
    store.put({a:6, b:6, c:7}, [5, 6]);
    log("This browser supports using array keys.")
  } catch (e) {
    elog("This browser does not support using array keys: " + e.message);
  } 
  
  try {
    var store = db.createObjectStore("compound-index");
    var acIndex = store.createIndex("by_ac", ["a", "c"]);
    store.put({a:6, c:7}, "foo");
    
    log("This browser supports puts when compound indexes are present.")
    
    try {
      var ireq = acIndex.get([6,7]);
      ireq.onerror = function (e) {
        console.log(e); 
        elog("This browser does not support lookup of objects via compound index" + e.message);
      };
      ireq.onsuccess = function (e) {
        if (_.isEqual(e.target.result, {a:6, c:7})) {
          log("This browser supports lookup of objects via compound index");
        } else {
          elog("This browser does not support lookup of objects via compound index");
        }
      };
    } catch (e) {
      console.log(e);
      elog("This browser does not support lookup of objects via compound index: " + e.message);
    }
  } catch (e) {
    elog("This browser does not support compound indexes: " + e.message);
  }
};


            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console