source: https://openjavascript.info/2022/06/09/pass-data-from-one-html-page-to-another/

Access a user’s web storage with window.localStorage or window.sessionStorage (~5MB)

Make data persistent across pages with localStorage

Saving to local storage

To save to local storage space in a user’s browser, call the setItem method.

Items are saved in key-value pairs. When using setItem, you specify the key first and then pass in the data to be stored.

/* Saving data to local storage */

const myData = "Use localStorage to make data persistent!";

localStorage.setItem('test-item', myData);

console.log(localStorage);
// {
//   "test-item": "Use localStorage to make data persistent!"
// }

Retrieving from local storage

Now, on the next page, you can retrieve the item again.

For this, use getItem and pass in the key value of the data item you want to retrieve:

/* Retrieving from local storage */

const myData = localStorage.getItem('test-item');

console.log(myData);
// {
//  "test-item": "Use localStorage to make data persistent!"
// }