Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable a built-in function in javascript (alert)

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

Can I do this?

More importantly, is it right to do this?

What about strict mode?

like image 926
Félix Saparelli Avatar asked Nov 29 '25 11:11

Félix Saparelli


2 Answers

Yes, you can disable or overwrite alert(). No, it's not right to do it, except in some bizarre and limited situations.

Disable:

window.alert = function() { }; 

Override:

window.alert = function(text) { /* do something */ };
like image 156
jball Avatar answered Dec 01 '25 02:12

jball


Yes you can, it's your choice. You could also store the original 'alert':

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

now the old alert is still usable: nativeAlert('something');

like image 41
KooiInc Avatar answered Dec 01 '25 01:12

KooiInc