Has anyone got any experience with overriding the alert()
function in JavaScript?
I have faced a requirement to show a default message along with the actual alert messages. This is how I managed to do it.
const actualAlertFunc = window.alert;
window.alert = function(msg) {
actualAlertFunc('some default message '+ msg);
}
I have tested it on chrome. I am not sure whether its a good practise, but it serves the purpose.