简体   繁体   中英

Is it possible to store information client-side?

I'm pretty new to programming so I'm unsure if this is a stupid question or not, but is it possible to store information on the client side? Through JavaScript somehow?

For example say you wanted to create something basic like a to-do list or an alarm clock app. Would you need to use PHP or Rails or something to create that or is it possible to store that information on the client-side? If so would I use JavaScript?

Yep! You can use sessionStorage: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

or localStorage: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

to store data client-side. It's very easy to use too!

是的,带有HTML5本地存储和cookie。

I you wish to store information locally you can do so at the variable localSotrage .

To write information use:

localStorage.setItem(name, value);

To read information use:

localStorage.getItem(name); //Returns item value

To remove information use:

localStorage.setItem(name);

Keep in mind that localStorage stores information across the whole domain . For example, if you store the variable potato at www.mydomain.com/main , then you can retrieve it at www.mydomain.com/potato .
I hope this helps you out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM