Saving Text to Session If The Page Is Accidentally Refreshed
Get the text field that you want to track
let field = document.getElementById('field');
Assign value to the field if accidentally refreshed the page
if(sessionStorage.getItem('autosave')){ field.value = sessionStorage.getItem('autosave'); }
Save value to session when field value change
field.addEventListener('change', function(){ sessionStorage.setItem('autosave', field.value); });