Home >Web Front-end >JS Tutorial >js implements reminder of unsaved information when leaving the page (reduces user repeated operations)_javascript skills
js implements reminder of unsaved information when leaving the page (reduces user repeated operations)_javascript skills
//Leave Determine whether there are unsaved input values when page var hasSaved = false;//Whether there is an unsaved flag for input content, the initial value is false function CheckUnsave(){ if(hasSaved==false ){ alert("What you uploaded has not been saved, please save it before leaving the page"); return false;} //return true; //This statement cannot be added }
//Change the state after saving function ChangeState() { hasSaved = true; }
Add the attribute onbeforeunload to the body Html code
Call ChangeState before submitting the action. If you press a certain button and leave the page, you will no longer be reminded. For example, if you press the save button, you need to modify the status of the save identifier after pressing the save button: Html code
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn