From: http://www.fayland.org/journal/AutoSave.html
This function is common. It is to prevent the loss of things that have worked so hard to write due to browser crash or failed submission. This is also in Gmail.
The principle is to store the content in the text box into a Cookie. If it is not submitted successfully (probably because the browser crashes), the next time you access the page, you will be asked whether to import the last stored content.
Function AutoSave (it) {// it indicates the called text box
Var _ value = it. value; // obtain the value of the text box.
If (! _ Value ){
Var _ LastContent = GetCookie ('autosavecontent'); // obtain the cookie value. Here, GetCookie is a custom function. For more information, see the source code.
If (! _ LastContent) return; // If the cookie has no value, it indicates it 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: set this cookie.
Document. cookie = "AutoSaveContent =" + escape (_ value) + expires;
}
}
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="70" wrap="virtual" onkeyup="AutoSave(this);" onselect="AutoSave(this);" onclick="AutoSave(this);"></textarea>
<input type="submit"></form>
The first statement imports js, and the second sentence's onSubmit indicates that the cookie will be deleted if it is submitted, and the DeleteCookie is also a custom function. See source code.
In textarea, onkeyup is used to access AutoSave when a key is clicked to store newly written text.
Onselect and onclick are used to determine the automatically saved text during the new access.
This is generally the case. Enjoy!
Source code: http://www.fayland.org/javascript/AutoSave.js