I am having trouble finding a way to store persistent settings for an office.js add-in on Mac.
On windows localStorage works perfect as it saves settings that persist through closing and opening Word.
On Mac localStorage does not persist closing and opening Word, not even through a refresh or closing and opening of the add-in.
Here is a simple code sample:
var settingString = 'mySetting';
var oldValue = localStorage.getItem(settingString);
write('oldValue: "' + oldValue + '"');
var d = new Date();
var newValue = d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
localStorage.setItem(settingString, newValue);
write('newValue: "' + newValue + '"');
iOS currently has a bug that's preventing us from fixing this localStorage issue yet. In the meantime, you have two potential workarounds:
Cookies
If you want the setting to be persisted across documents, use JavaScript cookies (w3schools doc) until the bug is fixed:
Settings
If it's sufficient for you to persist the value only in the current document, you can use the Office Settings API (Office.js Settings object doc):
-Michael Saunders, program manager for Office add-ins