I have the following body unload event listener
window.onbeforeunload = () => {
return "Changes you made may not be saved.";
};
How do I remove that particular one when I'm done with the background processing I have to do?
I have the following body unload event listener
window.onbeforeunload = () => {
return "Changes you made may not be saved.";
};
How do I remove that particular one when I'm done with the background processing I have to do?
To remove an event listener(like you mentioned incase of multiple eventlisteners), you need to name your event handler function to an external function, not anonymous (so that you can reference that function):
Update 1:- I have added the message to be followed on screen
window.addEventListener("beforeunload", customFunction);
function customFunction(event){
event.preventDefault();
return event.returnValue = "Are you sure you want to exit?";
}
window.removeEventListener("beforeunload",customFunction);