it looks like you have multiple apps / websites running from the same source. local storage uses a policy of the same origin, that is, all your scripts from the same source will have access to the same data.
Data placed in local storage is the source (a combination of protocol, host name and port number, as defined in the same policy source) (data is available for all scripts downloaded from pages from the same origin that previously stored data) and saved after browser is closed.
from Wikipedia: web storage
because your different application scripts use the same local storage, they must store the data so that it does not conflict with each other.
Option A. Use one local storage key for each application / website
This option will be recommended. MDN: DOM Storage Guide says:
Keep in mind that everything you store in any repository described on this page is converted to a string using its .toString before storing. Therefore, an attempt to save a shared object will result in the string "[Object Object]" being saved instead of the object or its JSON representation. Using native JSON analysis and the serialization methods provided by the browser are a good and common way to store objects in string format.
use one json array for all strings and save it under one key in local storage. add rows, parse json, add data to the array and save them as a string in local storage. this way your application will use only one key in local storage, which should be unique to your application.
json should look something like this:
[ {Plan: 1, Reward: 1}, {Plan: 2, Reward: 2}, {Plan: 3, Reward: 3}, ]
add lines:
var dataStr = localStorage.getItem('APPNAME-DATA'); var data = JSON.parse(dataStr); data.push({Plan: 4, Reward: 4}); dataStr = JSON.stringify(data); localStorage.setItem('APPNAME-DATA', dataStr);
I see that you are using the key name for the data-index attribute of the table cell. since there are no key names in this solution, save the key-name in the object as well. for example: data.push({Key: 'keyname', Plan: 4, Reward: 4}); . Ideally, use a different name with a larger value than Key .
Option B. Use the prefix for local storage keys
name the keys APPNAME-KEYNAME . later, when you APPNAME- over the keys, check if the key name begins with APPNAME- . if you do not continue the next element.
... for (i = 0; i < ORMcount; i += 1) { var key = localStorage.key(i); //Get Key if ( key.indexOf('APPNAME-') !== 0 ) { continue; } ...