1

I need to write a JavaScript module that rotates banner images displayed in a SharePoint web part. I would like to rely on SharePoint APIs as little as possible, and keep as much as possible self contained in the JavaScript module that drives the web part. I would like to keep track of the last time my code advanced to the next image in a list, and what that image was. The list will itself will be persisted in SharePoint and available through the REST API.

So, in the modern browser JavaScript runtime environment, is there any means of locally persisting the small record I describe above?

ProfK
  • 49,207
  • 121
  • 399
  • 775

1 Answers1

1

There are a few ways. But, for something like this, I would go with localStorage. For instance:

localStorage.setItem('lastSlide', JSON.stringify({
  time: +new Date,
  src: 'http://lorempixel.com/100/100'
}));

// Then, to retrieve:
var lastSlide;
try {
  lastSlide = JSON.parse(localStorage.getItem('lastSlide'));
} catch(e) { /* ... */}
rgthree
  • 7,217
  • 17
  • 21