UNPKG

1.09 kBHTMLView Raw
1<!doctype html>
2<html>
3 <head>
4 <meta charset="utf8" />
5 <title>Simple localForage example</title>
6 </head>
7 <body>
8 <script src="../dist/localforage.js"></script>
9 <script>
10 // Forcing IndexedDB here.
11 localforage.setDriver(localforage.INDEXEDDB).then(function() {
12 var key = 'STORE_KEY';
13 var value = new Uint8Array(8);
14 value[0] = 65
15 var UNKNOWN_KEY = 'unknown_key';
16
17 localforage.setItem(key, value, function() {
18 console.log('Saved: ' + value);
19
20 // causes InvalidState erros
21 localforage._dbInfo.db.close();
22
23 localforage.getItem(key).then(function(readValue) {
24 console.log('Read: ', readValue);
25 }).catch(function(err) {
26 console.error('Read: ', err);
27 });
28
29 // Since this key hasn't been set yet, we'll get a null value
30 localforage.getItem(UNKNOWN_KEY).then(function(err, readValue) {
31 console.log('Result of reading ' + UNKNOWN_KEY, readValue);
32 });
33 });
34 });
35 </script>
36 </body>
37</html>