I am trying to remove event using window.removeEventListener which I have added using window.addEventListener for event beforeunload but it is not getting removed. I am trying following code
addAlertWithListener(){
window.addEventListener('beforeunload', (event) => {
// Cancel the event as stated by the standard.
event.preventDefault();
// Chrome requires returnValue to be set.
event.returnValue = 'You are currently in edit mode. Are you sure you want to refresh the page?';
},true);
}
It is being added but when I am trying to remove the same function using below code :
removeAlertWithListener() {
window.removeEventListener('beforeunload', null,true);
}
It still gives alert message. Am I missing something over here? I tried with and without last param. None of the thing seems working here.