Skip to content

Instantly share code, notes, and snippets.

@camilokawerin
Forked from codepo8/localstorage.js
Created August 26, 2010 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camilokawerin/550721 to your computer and use it in GitHub Desktop.
Save camilokawerin/550721 to your computer and use it in GitHub Desktop.
<script>
// test for localStorage support
if(('localStorage' in window) && window['localStorage'] !== null){
var f = document.getElementById('mainform');
// test with PHP if the form was sent (the submit button has the name "sent")
<?php if(isset($_POST['sent'])){?>
// get the HTML of the form and cache it in the property "state"
localStorage.setItem('state',f.innerHTML);
// if the form hasn't been sent...
<?php }else{ ?>
// check if a state property exists and write back the HTML cache
if('state' in localStorage){
f.innerHTML = localStorage.getItem('state');
}
<?php } ?>
}
</script>
@camilokawerin
Copy link
Author

I´ve removed an extra ")" from php if :)

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