how to store local storage for all browsers code example

Example 1: javascript localstorage

localStorage.setItem("user_name", "Bob");

document.body.addEventListener("click", function(){
  alert(localStorage.getItem("user_name"))
});

Example 2: localstorage

// using in HTML5 (frontend)

// set
localStorage.setItem('users', 'vilh'); 

users = [
	{
    	id: 1,
        name: 'vilh',
    },
    {
    	id: 2,
        name: 'zidane'
    },
]

// set string 
localStorage.setItem('users', users);	// stored objects
localStorage.setItem('users', JSON.stringify(users));	// stored string

// get
var retrievedUsername = localStorage.getItem('users');