在网站中嵌入JS控制台 [英] Embed JS Console within website
本文介绍了在网站中嵌入JS控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在网站中嵌入JS控制台以进行扩展调试。是否有任何库或钩子可用?如何捕获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?
推荐答案
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);
};
这里是工作示例。它记录对 console.log
在 .output
元素中的调用,以及在控制台中像往常一样。
Here's a working example. It logs calls to console.log
in the .output
element, as well as in the console like usual.
这篇关于在网站中嵌入JS控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文