开发者

Disable a built-in function in javascript (alert)

开发者 https://www.devze.com 2023-01-28 12:04 出处:网络
Simple: I want to disable/overwrite alert(). Can I do this? More importantly, is it right to do this? What ab开发者_如何学JAVAout strict mode?Yes, you can disable or overwrite alert(). No, it\'s no

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

Can I do this?

More importantly, is it right to do this?

What ab开发者_如何学JAVAout strict mode?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号