Home >Web Front-end >JS Tutorial >AutoSave/automatic storage function implementation_javascript skills
Reprinted from: http://www.fayland.org/journal/AutoSave.html
This function is very common. This is to prevent the browser from crashing or submitting unsuccessfully, causing the things you have worked so hard to write to disappear. This is also available in Gmail.<p> // SetCookie 这里就是设置该 cookie<br> document.cookie = "AutoSaveContent=" + escape (_value) + expires;<br> }<br>}</p>And this HTML should be like this:
<br><script language=JavaScript src='/javascript/AutoSave.js'></script><br><form action="submit" method="POST" onSubmit="DeleteCookie('AutoSaveContent')"><br><textarea rows="5" cols="70" wrap="virtual" onkeyup="AutoSave(this);" onselect="AutoSave(this);" onclick="AutoSave(this);"></textarea><br><input type="submit"></form><br>The first sentence imports js, and the onSubmit in the second sentence refers to if it is submitted Delete the cookie, and DeleteCookie is also a custom function. See source code.
That’s about it. Enjoy!
Source code: http://www.fayland.org/javascript/AutoSave.js