get, set, del
). CrossStorageHub.init([ { origin: /\.example.com$/, allow: ['get'] }, { origin: /:(www\.)?example.com$/, allow: ['get', 'set', 'del'] } ]);
var storage = new CrossStorageClient('https://store.example.com/hub.html'); storage.onConnect().then(function() { // Set a key with a TTL of 90 seconds return storage.set('newKey', 'foobar', 90000); }).then(function() { return storage.get('existingKey', 'newKey'); }).then(function(res) { console.log(res.length); // 2 }).catch(function(err) { // Handle error });
onConnect
method returns a promise that is executed when the connection to the hub has been established. You can also call storage.close
at the end of the connection, which is implemented using an iframe
.cross-storage
, author: Daniel St. JulesSource: https://habr.com/ru/post/236223/
All Articles