Home > Uncategorized > Auto save the contents of a text field, and if the browser is accidentally refreshed, restore the text field contents so that no writing is lost

Auto save the contents of a text field, and if the browser is accidentally refreshed, restore the text field contents so that no writing is lost


 

// Get the text field that we’re going to track
var 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”);
}

// Check the contents of the text field every second
setInterval(function(){
// And save the results into the session storage object
sessionStorage.setItem(“autosave”, field.value);
}, 1000);

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: