Pregunta

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!

¿Fue útil?

Solución

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.

Otros consejos

use session storage. It stores values as key, value pairs. To set the value to session use

sessionStorage.name = "Use Name";
sessionStorage.APIKey = "Use APIKey";

To Get the values from session storage:

var name = sessionStorage.name;
var APIKey = sessionStorage.APIKey;

Note: Name/value pairs are always stored as strings. Remember to convert them to another format when needed!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top