Skip to content

Instantly share code, notes, and snippets.

@jamsajones
Last active December 11, 2015 22:29
Show Gist options
  • Save jamsajones/4670301 to your computer and use it in GitHub Desktop.
Save jamsajones/4670301 to your computer and use it in GitHub Desktop.
(function(){
function do_save(name) {
localStorage.setItem(name, document.body.innerHTML)
}
window.addEventListener('load', function() {
var name = window.location.pathname || 'baseobject',
content = localStorage.getItem(name),
save = undefined
if(content !== null) {
document.body.innerHTML = content
}
document.body.addEventListener('keypress',function(){
if(save !== undefined){
clearTimeout(save)
}
save = setTimeout(do_save.bind(undefined,name), 500)
})
document.body.addEventListener('unload', do_save.bind(undefined,name))
})
})()
<!DOCTYPE html>
<html contenteditable>
<head>
<script src="content-editable.js"></script>
</head>
<body>
<p>Your inital message here.</p>
</body>
</html>
@jamsajones
Copy link
Author

Just did this based on something I read on a blog. (https://coderwall.com/p/lhsrcq) It is hosted at codefarm.net. Silly but I thought it was something to put on my empty site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment