本文介紹了監(jiān)聽控制臺.log的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我想為 console.log()
設(shè)置一個偵聽器,并在不阻止默認行為的情況下處理消息.因此,開發(fā)工具的控制臺也應(yīng)該收到消息.有什么想法嗎?
I want to set a listener for console.log()
and do something with the message without preventing the default behaviour. So, the console of the dev tools should get the message as well. Any ideas?
推薦答案
從來沒有在網(wǎng)頁中嘗試過這個,但是它可以在瀏覽器插件中工作(出于安全原因,javascripts 權(quán)限并不相同).
Never tried this in a webpage, but it work in a browser plugin (where javascripts rights are are not the same for security reasons).
你絕對可以這樣做:
(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 的有趣之處在于函數(shù)也是對象:D
The funny thing in javascript is that function are objects too :D
這篇關(guān)于監(jiān)聽控制臺.log的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!