I am working on a script that handles unsaved text inputs.
Here is the code for the 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?";
}
}
}
}
Later, I use it in another script like this:
`window.onbeforeunload = Unsave.unsave_check();`
However, despite seeing that function unloadPage()
is never called, why is that so?
I notice that the value of unsaved changes to true, but I still do not receive an alert message when trying to go back.
How can I address this issue?
Thank you for your help!