[removed] Overriding alert()

后端 未结 12 2067
忘了有多久
忘了有多久 2020-11-22 03:17

Has anyone got any experience with overriding the alert() function in JavaScript?

  • Which browsers support this?
  • Which browser-versions sup
12条回答
  •  清酒与你
    2020-11-22 04:06

    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.

提交回复
热议问题