Has anyone got any experience with overriding the alert()
function in JavaScript?
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(){}