我想为console.log()设置一个侦听器,并在不阻止默认行为的情况下对消息执行一些操作。因此,开发工具的控制台也应该得到该消息。有什么想法吗?
发布于 2011-06-23 22:27:54
从未在网页中尝试过,但它在浏览器插件中有效(出于安全原因,javascripts权限是不同的)。
你完全可以选择这样的东西:
(function(){
var originallog = console.log;
console.log = function(txt) {
// Do really interesting stuff
alert("I'm doing interesting stuff here !");
originallog.apply(console, arguments);
}
})();javascript中有趣的是函数也是对象:D
发布于 2011-06-23 22:28:29
这是一个小技巧,但我不确定有没有更好的解决方案:
console._log_old = console.log
console.log = function(msg) {
alert(msg);
console._log_old(msg);
}https://stackoverflow.com/questions/6455631
复制相似问题