1234567891011121314151617181920212223242526272829303132333435 |
- <!doctype html>
- <html>
- <head>
- <meta charset="utf8" />
- <title>Simple localForage example</title>
- </head>
- <body>
- <script src="../dist/localforage.js"></script>
- <script>
- // Forcing localstorage here. Feel free to switch to other drivers :)
- localforage.setDriver(localforage.LOCALSTORAGE).then(function() {
- var key = 'STORE_KEY';
- // var value = 'What we save offline';
- var value = new Uint8Array(8);
- value[0] = 65
- // var value = undefined;
- var UNKNOWN_KEY = 'unknown_key';
-
- localforage.setItem(key, value, function() {
- console.log('Saved: ' + value);
-
- localforage.getItem(key, function(err, readValue) {
- console.log('Read: ', readValue);
- });
-
- // Since this key hasn't been set yet, we'll get a null value
- localforage.getItem(UNKNOWN_KEY, function(err, readValue) {
- console.log('Result of reading ' + UNKNOWN_KEY, readValue);
- });
- });
- });
- </script>
- </body>
- </html>
|