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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:43:34
Original
1461 people have browsed it
Javascript code
Copy code The code is as follows:

//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
Copy code The code is as follows:



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
Copy code The code is as follows:


Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template