JavaScript:覆盖警报() [英] JavaScript: Overriding alert()
本文介绍了JavaScript:覆盖警报()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有人有过在JavaScript中覆盖 alert()
函数的经验?
Has anyone got any experience with overriding the alert()
function in JavaScript?
- 哪些浏览器支持此功能?
- 哪些浏览器版本支持此功能?
- 覆盖此功能有哪些危险?
推荐答案
这绝对是支持的。这是你的网页,你可以随心所欲地做任何事情。
It's definitely "supported". It is your web page, you do whatever you want to with it.
我已经这样做了,无需修改图书馆就可以跟踪分析事件,但可以潜入事件。
I already did this to track analytics events without modifying a library but by sneaking into events.
使用代理模式:
(function(proxied) {
window.alert = function() {
// do something here
return proxied.apply(this, arguments);
};
})(window.alert);
如果需要(代理)
此处有更多信息: JQuery Types #Proxy Pattern
这篇关于JavaScript:覆盖警报()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文