本文介紹了在網站內嵌入 JS 控制臺的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想在網站中嵌入 JS-Console 以進行擴展調試.有沒有可用的庫或鉤子?如何捕獲 console.log 消息?
I want to embed a JS-Console within a website for extended debugging purposes. Are there any libraries or hooks available? How can I catch console.log messages?
推薦答案
如何捕獲 console.log 消息?
How can I catch console.log messages?
你可以給真正的 console.log
方法打猴子補丁,然后對輸入做任何你喜歡的事情:
You can monkey-patch the real console.log
method and do whatever you like with the input:
var realConsoleLog = console.log;
console.log = function () {
var message = [].join.call(arguments, " ");
// Display the message somewhere... (jQuery example)
$(".output").text(message);
realConsoleLog.apply(console, arguments);
};
這是一個工作示例.它記錄對 .output
元素中的 console.log
的調用,以及像往常一樣在控制臺中的調用.
Here's a working example. It logs calls to console.log
in the .output
element, as well as in the console like usual.
這篇關于在網站內嵌入 JS 控制臺的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!