Setting session variable using javascript

后端 未结 4 564
被撕碎了的回忆
被撕碎了的回忆 2020-12-08 14:50

I am getting name and email id of a user after he logs in via facebook to my website.. I want to add those variables in session on login form itself using javascript; I tri

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 15:28

    It is very important to understand both sessionStorage and localStorage as they both have different uses:

    From MDN:

    All of your web storage data is contained within two object-like structures inside the browser: sessionStorage and localStorage. The first one persists data for as long as the browser is open (the data is lost when the browser is closed) and the second one persists data even after the browser is closed and then opened again.

    sessionStorage - Saves data until the browser is closed, the data is deleted when the tab/browser is closed.

    localStorage - Saves data "forever" even after the browser is closed BUT you shouldn't count on the data you store to be there later, the data might get deleted by the browser at any time because of pretty much anything, or deleted by the user, best practice would be to validate that the data is there first, and continue the rest if it is there. (or set it up again if its not there)

    To understand more, read here: localStorage | sessionStorage

提交回复
热议问题