最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to clear local storage when deleting user - Stack Overflow

programmeradmin1浏览0评论

I am building a simple react app with a rails backend. If I give the user the option to delete his/her account, how can I simultaneously clear local storage?

Is that a back end function or can I do something on front end?

Any advice is greatly appreciated!

I am building a simple react app with a rails backend. If I give the user the option to delete his/her account, how can I simultaneously clear local storage?

Is that a back end function or can I do something on front end?

Any advice is greatly appreciated!

Share Improve this question asked Jun 22, 2017 at 4:24 peterchicpeterchic 4171 gold badge4 silver badges11 bronze badges 3
  • 1 Why would something that is clearly client-side storage require a "back end function" to manipulate...? – Patrick Roberts Commented Jun 22, 2017 at 4:26
  • @PatrickRoberts because it'd be really useful to be able to do so :) The W3C currently have a working draft spec to do just this: w3/TR/clear-site-data – Dom Christie Commented Jun 22, 2017 at 7:51
  • @DomChristie I feel violated... (kidding, but this draft honestly does seem superfluous.) – Patrick Roberts Commented Jun 22, 2017 at 7:56
Add a ment  | 

2 Answers 2

Reset to default 7

localStorage stores data into browser's or system's storage which is local to your system. So no backend process will be required. You can simply use clear() function to clear the stored data.

localStorage.clear(); //for localStorage
sessionStorage.clear(); //for sessionStorage

You can use localStorage.clear();

发布评论

评论列表(0)

  1. 暂无评论