UNPKG

1.05 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 localstorage here. Feel free to switch to other drivers :)
11 localforage.setDriver(localforage.LOCALSTORAGE).then(function() {
12 var key = 'STORE_KEY';
13 // var value = 'What we save offline';
14 var value = new Uint8Array(8);
15 value[0] = 65
16 // var value = undefined;
17 var UNKNOWN_KEY = 'unknown_key';
18
19 localforage.setItem(key, value, function() {
20 console.log('Saved: ' + value);
21
22 localforage.getItem(key, function(err, readValue) {
23 console.log('Read: ', readValue);
24 });
25
26 // Since this key hasn't been set yet, we'll get a null value
27 localforage.getItem(UNKNOWN_KEY, function(err, readValue) {
28 console.log('Result of reading ' + UNKNOWN_KEY, readValue);
29 });
30 });
31 });
32 </script>
33 </body>
34</html>