Disable a built-in function in javascript (alert)

余生长醉 提交于 2019-11-29 08:07:36

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 */ };

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');

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!