Saving values from a session JavaScript

I have a website and what I need to do is: whenever a user browses over a URL that contains a particular string (let’s say “-post-update”) I want to capture some credentials from that page. Now when the user closes the browser and comes back, I want to get the saved credentials back. How can I do it in JavaScript?

Answer

Unless you’re wanting to sent a list of all page headers with every request to your server, you’ll probably be better off using localstorage to achieve this objective. Look at that link for a reference, but the basic idea is as follows:

const headings = localStorage.getItem('pageHeadings').split(',')
console.log(headings)
headings.append(window.title)
localStorage.setItem('pageHeadings', headings.join(','))