Last active
September 19, 2025 16:18
-
-
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'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(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