/*\ |*| |*| :: cookies.js :: |*| |*| A complete cookies reader/writer framework with full unicode support. |*| |*| https://developer.mozilla.org/en-US/docs/DOM/document.cookie |*| |*| This framework is released under the GNU Public License, version 3 or later. |*| http://www.gnu.org/licenses/gpl-3.0-standalone.html |*| |*| Syntaxes: |*| |*| * docCookies.setItem(name, value[, end[, path[, domain[, secure]]]]) |*| * docCookies.getItem(name) |*| * docCookies.removeItem(name[, path], domain) |*| * docCookies.hasItem(name) |*| * docCookies.keys() |*| \*/
// 页面A var db = null; var request = indexedDB.open("message"); request.onsuccess = (e) => db = e.target.result; request.onupgradeneeded = function(event) { db = event.target.result; if (!db.objectStoreNames.contains('message')) { db.createObjectStore('message', { keyPath: 'key' }); } };
functionsetData(data){ var transaction = db.transaction(['message'], 'readwrite'); var store = transaction.objectStore(['message']); var requestData = store.put({ key: "msg", info: data}); requestData.onsuccess = function(e) { console.log(e.target.result); }; };
setTimeout(() =>setData(1),1000);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// 页面B var db = null; var request = indexedDB.open("message"); request.onsuccess = (e) => db = e.target.result; functionreadMsg(){ var transaction = db.transaction(['message']); var objectStore = transaction.objectStore('message'); var requestResult = objectStore.get('msg');