Turn from: http://www.fayland.org/journal/AutoSave.html
This feature is very common. is to prevent the browser from crashing or submitting unsuccessful and the things that cause you to write away. That's the same thing in Gmail.
It works by storing the contents of the text box into a Cookie. If the failure to commit succeeds (possibly because of a browser crash), the next time you visit the page, ask if you want to import the last thing that was stored.
function AutoSave (IT) {//It refers to the text box called
var _value = It.value; Get the value of a text box
if (!_value) {
var _lastcontent = GetCookie (' autosavecontent '); Get the value of the cookie, here's GetCookie is a custom function, see source code
if (!_lastcontent) return; If the cookie does not have a value, the description is a new start
if (Confirm ("Load last AutoSave Content?") {//otherwise ask whether to import
It.value = _lastcontent;
return true;
}
} else {
var expdays = 30;
var exp = new Date ();
Exp.settime (Exp.gettime () + (Expdays * 86400000)); 24*60*60*1000 = 86400000
var expires= '; Expires= ' + exp.togmtstring ();
Setcookie This is where you set this cookie
Document.cookie = "autosavecontent=" + Escape (_value) + expires;
}
}
And this should be the case in HTML:
<script language=javascript src= '/javascript/autosave.js ' ></script>
<form action= "Submit" method= "POST" onsubmit= "Deletecookie (' autosavecontent ')" >
<textarea rows= "5" cols= "wrap=" virtual "onkeyup=" AutoSave (This), "onselect=" AutoSave (this); "onclick=" AutoSave (this); " ></textarea>
<input type= "Submit" ></form>
The first sentence to import JS, the second sentence of OnSubmit refers to the deletion of the cookie if committed, and Deletecookie is also a custom function. See source code.
The onkeyup in textarea refers to accessing the AutoSave when the key is pressed to store the newly written text.
Onselect and onclick are used to determine the text that is automatically saved when you use the new access.
This is roughly the case. enjoy!
Source code: Http://www.fayland.org/javascript/AutoSave.js