Window.sessionStorage

The sessionStorage property allows you to access a session Storage object. sessionStorage is similar to Window.localStorage, the only difference is while data stored in localStorage has noexpiration set, data stored in sessionStorage gets cleared when the page session ends. A page session lasts for as long as the browser is openand survives over page reloads and restores. Opening a page in a new tab or window will cause a new session to be initiated, which differs from how session cookies work.

// Get the text field that we're going to trackvar field = document.getElementById('field');// See if we have an autosave value// (this will only happen if the page is accidentally refreshed)if (sessionStorage.getItem('autosave')) { // Restore the contents of the text field field.value = sessionStorage.getItem('autosave');}// Listen for changes in the text fieldfield.addEventListener('change', function() { // And save the results into the session storage object sessionStorage.setItem('autosave', field.value);});