Please help me add the code so that the values ​​that are displayed are stored on other pages of sites through localStorage. The code itself:

var str = location.search; if(str.indexOf('city') + 1) { document.getElementById('go').innerHTML = 'текст 1'; } else if (str.indexOf('city2') + 1) { document.getElementById('go').innerHTML = 'текст 2'; } 

1 answer 1

Well, adding data to localStorage. The first parameter is the key, the second is the value.

 window.localStorage.setItem("city", "текст 1"); window.localStorage.setItem("city2", "текст 2"); 

To get data from the repository, use getItem :

 window.localStorage.getItem("city");