-
-
Save oddlyzen/588368 to your computer and use it in GitHub Desktop.
This file contains 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
<script> | |
// test for localStorage support | |
if(('localStorage' in window) && window['localStorage'] !== null){ | |
var f = document.getElementById('mainform'); | |
// test with Ruby if the form was sent (the submit button has the name "sent") | |
<% if params[: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... | |
<% else %> | |
// check if a state property exists and write back the HTML cache | |
if('state' in localStorage){ | |
f.innerHTML = localStorage.getItem('state'); | |
} | |
<% end %> | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment