I have ts script with code to handle "unsaved"
text inputs
Here is code of script
export class Unsave {
public static unsave_check(): void {
let unsaved = false;
$(":input").change(function(){
unsaved = true;
console.log(unsaved);
});
function unloadPage(){
if(unsaved){
return "You have unsaved changes on this page. Do you want to leave this page and discard your changes or stay on this page?";
}
}
}
}
And then I use it in other script like this
`window.onbeforeunload = Unsave.unsave_check();`
But as I see, function unloadPage()
is never hit, why so?
I see that unsaved is changing value to true. But when I go back, I get no alert message.
How I can fix this issue?
thank's for help