Disable inline function in javascript (alert)

Simple: I want to disable / overwrite alert() .

Can I do it?

More importantly, is this the right thing to do?

How about high security?

+3
javascript overwrite alert strict
source share
2 answers

Yes, you can disable or overwrite alert() . No, this is wrong to do, except in some strange and limited situations.

Disable:

 window.alert = function() { }; 

Redefinition:

 window.alert = function(text) { /* do something */ }; 
+6
source share

Yes you can, it's your choice. You can also keep the original β€œwarning”:

 window.nativeAlert = window.alert; window.alert = function(val){console.log(val+' (alert disabled)');}; 

now the old warning can still be used: nativeAlert('something');

+7
source share

All Articles