I'm working on a corporate intranet site and am trying to create a page that will warn a user on window unload if they have not saved thier work. Basically I just select all inputs, and on change, set var changes = true; On window unload if changes==true, they have made changes that are not yet saved, and I want a confirm box to pop up, asking if they really want to leave or stay on the page? At this point is it to late to cancel the window unload? My code is below:
- window.onunload=checkChanges;
-
var changes=false;
-
-
function checkChanges(){
-
if(changes==true){//changes have been made
-
if(!confirm("Do you want to leave without saving your changes?\n\nOK to Go, Cancel to stay on this page.")){
-
window.unload=false;
-
}
-
}
-
}
-
-
//while looping thru all inputs
-
inputs[x].onchange=function(){
-
changes=true;
-
};
I'm getting the proper confirm boxes, but I dont' know how to cancel the unload, if it's even possible.
Thanks,
Greg