Web Storage In HTML5

HTML5 provides us the property of web storage. It was also done by cookies but cookies is not the easy way to store large amount of data, because they are passed every request  to the server. Hence it was very slow to deal with cookies.

HTML provides us the facility in which the data is not passed by every server request, it is used only when we need this and it is easy to store large amount of data. The data is stored in the different part of the website and each website can access its own data. HTML5 uses javascript to store the data.

 

There are two types of objects for storing data.

Local storage

Session Storage

 

 

Local Storage: It stores data which has no limit. The data will be available next day, week and year

<!DOCTYPE html>

<html>

<body>

<script type="text/javascript">

localStorage.city="jaipur";

document.write("City: " + localStorage.city);

</script>

</body>

</html>

 

Session Storage: It stores data for one session. The data is deleted when the user closes the window.

<!DOCTYPE html>

<html>

<body>

<script type="text/javascript">

sessionStorage.city="jaipur";

document.write(sessionStorage.city);

</script>

</body>

</html>

Ebook Download
View all
Learn
View all