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?

2
  • 1
    keyword "local storage" Commented Dec 8, 2014 at 18:02
  • Thank you @AxelAmthor. I knew there was something I had forgotten, after some time out of client side, but googling for "something" would be so useless vs. "local storage". Commented Dec 8, 2014 at 19:00

1 Answer 1

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) { /* ... */}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.