Search code examples
javascripthtmlhttpapi-key

Save apikey between sessions


I'm making a little client-side web app for MagicCardMarket.eu. It's just javascript and html. The user has to log in using his username and apikey, though I was wondering what's the best way to save these between sessions?

It's the first time I make this kind of web app. It's also the first time I use anything like this apikey, so I wasn't sure what to Google.

Thanks!


Solution

  • You can use sessionStorage.

    sessionStorage.setItem('key','value');
    var value = sessionStorage.getItem('key');
    

    So what is it?

    This is a global object (sessionStorage) that maintains a storage area that's available for the duration of the page session. A page session lasts for as long as the browser is open and survives over page reloads and restores. Opening a page in a new tab or window will cause a new session to be initiated.