[removed] Overriding alert()

后端 未结 12 2287
忘了有多久
忘了有多久 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 03:59

    As said in many of the other answers, you can just override the function with

    window.alert = null
    

    or

    window.alert = function(){}
    

    however, this doesn't necessarily override the function on the prototype of the Window constructor (note the capital W), so the hacker can still type:

    Window.prototype.alert.apply(window, ["You were hacked!"]);
    

    therefore, you also need to override that function with:

    Window.prototype.alert = null
    

    or

    Window.prototype.alert = function(){}
    

提交回复
热议问题