navigate away alert without saving modifications
I'm developing a website in php.
I want to show a message something like javascript alert, when a user tries to edit or add something in a form and tries to navigate to some other section without saving the modification, i w开发者_运维问答ant to show a message to them,
that you are about to navigate about from this page, your modifications are not saved, do you want to continue?
how can i do this??
any one have an idea ???please share it with me..
Thanks
Use the beforeunload event. Pseudo-code:
window.onbeforeunload = function(e){
e = e || window.event;
// check if the user has edited sth
if(userHasEditedSomething()){
var msg = "You have unsaved changed. Do you want to navigate away from this page?";
e.returnValue = msg;
return msg;
}
}
Your job is to implement the userHasEditedSomething function that will return true when the user has unsaved changes (filled-in form fields) and false otherwise.
most of the browsers support this event
精彩评论