Skip to content

Instantly share code, notes, and snippets.

@jhammann
Last active September 19, 2025 16:18
Show Gist options
  • Select an option

  • Save jhammann/6000755 to your computer and use it in GitHub Desktop.

Select an option

Save jhammann/6000755 to your computer and use it in GitHub Desktop.
Save the current page state into your browser's local storage after you edited it's content with 'contenteditable'.
$(function(){
// this line isn't really necessary here but you have to append this attribute to the element you want the html stored of.
$("#wrapper").attr("contenteditable", "true")
var content = document.getElementById('wrapper');
// save the page's state after you're done with editing and clicked outside the content
$(content).blur(function() {
localStorage.setItem('page_html', this.innerHTML);
});
// pretty logical, getItem retrieves your local storage data
if (localStorage.getItem('page_html')) {
content.innerHTML = localStorage.getItem('page_html');
}
});
// this function resets the localstorage and thus resets the page back to it's original state.
function reset(){
localStorage.clear();
window.location = window.location;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment