开发者

Replace alert window

开发者 https://www.devze.com 2023-03-26 03:42 出处:网络
I use in my project third-party obfuscate开发者_Go百科d JS library. The matter is it uses standard alert window for notifications. My task is to replace this browser alert window with my custom. My so

I use in my project third-party obfuscate开发者_Go百科d JS library. The matter is it uses standard alert window for notifications. My task is to replace this browser alert window with my custom. My solution is:

alert = function(msg) {
    customAlert(msg);
}

Is there any another, may be better way to solve this problem?


This should be possible by overriding window.alert:

window.alert = function(msg) {
    console.log(msg);
}

Of course, it goes without saying that, if the library has already grabbed a reference to alert, it will be much harder to override (ex, because it has used (function() { var myalert = window.alert; … myalert("foo"); })())…

0

精彩评论

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