local-storage

Remove variables starting with a string from chrome.storage.local in JavaScript

泄露秘密 提交于 2020-01-06 07:55:29
问题 In a chrome extension, I store some variables in chrome.storage.local like this: chrome.storage.local.set({["name" + counter]: ""}, function() {}); (many thanks to Xan's answer regarding ES6 computed property names here), where counter is basically an incremented number. How can I use chrome.storage.local.remove to remove all the variables starting with "name" that were previously stored, when I don't need them anymore? Note: I use this type of storage ("name0", "name1", ...) as I can't store

Remove variables starting with a string from chrome.storage.local in JavaScript

痞子三分冷 提交于 2020-01-06 07:55:07
问题 In a chrome extension, I store some variables in chrome.storage.local like this: chrome.storage.local.set({["name" + counter]: ""}, function() {}); (many thanks to Xan's answer regarding ES6 computed property names here), where counter is basically an incremented number. How can I use chrome.storage.local.remove to remove all the variables starting with "name" that were previously stored, when I don't need them anymore? Note: I use this type of storage ("name0", "name1", ...) as I can't store

Chrome extensions: chrome.storage.local.get headache

有些话、适合烂在心里 提交于 2020-01-06 06:48:10
问题 Trying to build a simple Chrome extension to output the whole contents of localStorage. How difficult should it be? Spent a few hours researching and trying, still doesn't work :( Appreciate assistance! For example: function load() { chrome.storage.local.get(null, function(items) { var allKeys = Object.keys(items); alert(allKeys.count); }); } document.addEventListener('DOMContentLoaded', () => { load(); }); outputs 'undefined' Some other ways I tried actually contained an object, but I couldn

Remove a specific item from localstorage with js

主宰稳场 提交于 2020-01-06 05:39:07
问题 I am adding simple records to localstorage but I am having a hard time removing a specific item from my localstorage object. I am able to maintain the data on refresh and continue adding records no problem. I would like to add a button next to each entry that allows me to remove THAT particular record from localstorage and from my list. How would I accomplish this given the code below? var theLIst = document.getElementById('list'); var resetNotify = document.getElementById('reset-message');

Display JSON Array in HTML

与世无争的帅哥 提交于 2020-01-05 09:07:55
问题 I have a JSON array in localstorage . I want to retrieve this array, and display the values. The storage key is _myobject , and the value is [{"64508":"12:12:2"},{"5292":"12:17:34"}] What I want is to know how I can use JavaScript/jQuery to display/print the values in the following format: Number: 64508 - Time: 12:12:2 Number: 5292 - Time: 12:17:34 Could somebody please direct me on how I could do this? 回答1: You can use an Array.map to convert from your array into the string. Try something

jQ: Parse localstorage & stringify values

帅比萌擦擦* 提交于 2020-01-05 07:07:25
问题 I am storing some values in localStorage using stringify and I'm trying to parse them but it doesn't work for me. This is how I add the values: localStorage.setItem('a', JSON.stringify({ userid : '4361', value : '23' })); And this is how I parse them: $('p').text(JSON.parse(localStorage.getItem('a'))); Here is the fiddle: http://jsfiddle.net/hrHfG/ Also, I'd like to know how can I parse each value separately. For example, only the userid of 'a', or only the value, if its possible. Thanks a

jQ: Parse localstorage & stringify values

只愿长相守 提交于 2020-01-05 07:07:20
问题 I am storing some values in localStorage using stringify and I'm trying to parse them but it doesn't work for me. This is how I add the values: localStorage.setItem('a', JSON.stringify({ userid : '4361', value : '23' })); And this is how I parse them: $('p').text(JSON.parse(localStorage.getItem('a'))); Here is the fiddle: http://jsfiddle.net/hrHfG/ Also, I'd like to know how can I parse each value separately. For example, only the userid of 'a', or only the value, if its possible. Thanks a

atomic operation on window.localStorage

回眸只為那壹抹淺笑 提交于 2020-01-05 06:15:42
问题 Is this possible to do when setting 2 or more values? I am using phonegap and concerned that the user could kill the app while before it finishes setting both values. I realize that I could use W3C web sql with a transaction but didn't want the overkill of sql for what I am doing. 回答1: By default, no, there is no locking mechanism. However, you may want to check out this question also, and this site that it references. You would be better off with a SQL transaction if persistence of those

Implementing localStorage in my React application

泄露秘密 提交于 2020-01-05 05:37:48
问题 I'm currently doing the freeCodeCamp React challenge Building a Recipe Box. I have to fulfil the User Story of using HTML5 web storage to save changes made by the user so that even when the page is refreshed the changes remain. However I built my React Application without planning this beforehand , and now I'm stuck in a situation where I don't know how to add this functionality to my app. P.S I tried using global variables and setting state along with setting local storage . I'm new to React

How to subscribe on localStorage but not on sessionStorage events

青春壹個敷衍的年華 提交于 2020-01-05 03:24:30
问题 As far as I understand: window.addEventListener('storage', function(event){ ... }, false); is subscription on both localStorage and sessionStorage events. Can I subscribe on localStorage events only? Thanks. 回答1: I don't think you can, as you say storage is fired on the window when any storage item changes. You just have to check the storageArea property of the event when you receive it, and ignore the ones from session storage. E.g.: window.addEventListener('storage', function(event){ if