When should I use html5 sessionStorage?

后端 未结 2 1739
醉酒成梦
醉酒成梦 2021-02-01 21:14

I\'ve learned difference between sessionStorage (persist during session) and localStorage (persist forever if not deleted).

I can see that

2条回答
  •  没有蜡笔的小新
    2021-02-01 21:33

    The main reason to use sessionStorage is for cases where if your user were to open the same page twice in two different tabs, you'd want separate storage areas for those two tabs. For example, consider a site where you're buying a ticket (and you can only buy one ticket, like an airline ticket flow, as opposed to a case with a shopping cart). If the user tries to buy two tickets in two different tabs, you wouldn't want the two sessions interfering with each other. sessionStorage lets you track those session across multiple page loads independently.

提交回复
热议问题