Showing posts with label HTML Local Storage. Show all posts
Showing posts with label HTML Local Storage. Show all posts

Tuesday, December 6, 2016

JavaScript Session - HTML Local Storage - Q&A

Question:

What is a session and how does it works?

Answer

The sessionStorage is used for storing data on the client. The sessionStorage object is equal to the localStorage object, except that it stores the data for only one session. The data is deleted when the user closes the specific browser tab. For example;

if (sessionStorage.clickcount) {

    sessionStorage.clickcount = Number(sessionStorage.clickcount) + 1;

} else {

    sessionStorage.clickcount = 1;

}

JavaScript Session vs Cookie - Q&A

Question:

What are the differences between SESSION and COOKIE?
Where each of them is located?
Is it possible for another site to see others cookie?

Answer

In terms of capabilities, cookies only allow you to store strings. sessionStorage allow you to store JavaScript primitives but not Objects or Arrays (it is possible to JSON serialise them to store them using the APIs). Session storage will generally allow you to store any primitives or objects supported by your Server Side language/framework.
Cookies location.
Sessionstorage & localstorage location.
A properly designed browser will not allow a website to access another website's cookies, as this would violate the cross-domain policy and be a major security issue.