I have been working on a solution where I need to show custom text in beforeunload event. I have seen many questions here, but none of them seems to be working. So for angular is there any way using which we can update the text of the alert box? As I want to show the text in both English and French, depending upon language selection.
The code :
listenerFucntion = (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?';
}
addAlertWithListener(){
window.addEventListener('beforeunload', this.listenerFucntion ,true);
}
removeAlertWithListener() {
window.removeEventListener('beforeunload', this.listenerFucntion,true);
}
Here as you can see I am trying to change the text but all I am getting is :

Changing the message is no longer supported by the standard, so most (if not all) modern browsers will ignore this.
See the specifications here, particularly the note under point 8:
The message shown to the user is not customizable, but instead determined by the user agent. In particular, the actual value of the returnValue attribute is ignored.