本文介紹了監聽控制臺.log的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想為 console.log()
設置一個偵聽器,并在不阻止默認行為的情況下處理消息.因此,開發工具的控制臺也應該收到消息.有什么想法嗎?
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?
推薦答案
從來沒有在網頁中嘗試過這個,但是它可以在瀏覽器插件中工作(出于安全原因,javascripts 權限并不相同).
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 的有趣之處在于函數也是對象:D
The funny thing in javascript is that function are objects too :D
這篇關于監聽控制臺.log的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!