mirror of
https://github.com/localForage/localForage.git
synced 2026-01-25 14:44:26 +00:00
38 lines
1.1 KiB
HTML
38 lines
1.1 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf8" />
|
|
<title>Simple localForage example</title>
|
|
</head>
|
|
<body>
|
|
<script src="../dist/localforage.js"></script>
|
|
<script>
|
|
// Forcing IndexedDB here.
|
|
localforage.setDriver(localforage.INDEXEDDB).then(function() {
|
|
var key = 'STORE_KEY';
|
|
var value = new Uint8Array(8);
|
|
value[0] = 65
|
|
var UNKNOWN_KEY = 'unknown_key';
|
|
|
|
localforage.setItem(key, value, function() {
|
|
console.log('Saved: ' + value);
|
|
|
|
// causes InvalidState erros
|
|
localforage._dbInfo.db.close();
|
|
|
|
localforage.getItem(key).then(function(readValue) {
|
|
console.log('Read: ', readValue);
|
|
}).catch(function(err) {
|
|
console.error('Read: ', err);
|
|
});
|
|
|
|
// Since this key hasn't been set yet, we'll get a null value
|
|
localforage.getItem(UNKNOWN_KEY).then(function(err, readValue) {
|
|
console.log('Result of reading ' + UNKNOWN_KEY, readValue);
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|