[英]How to display console messages to the user?
有时会发生一些错误,我想向用户显示这些控制台消息,以便他们在截屏时可以看到错误消息(从我使用的框架或编写的console.log或正常的JavaScriprt错误)。 可能吗?
我只是想在控制台中向用户显示所有消息。
可能对您有帮助; 我使用下面的代码在新窗口上显示“错误”,而不是检查元素(控制台日志)。
//Handle Ajax Error
$(document).ajaxError(function(e, jqXHR,ajaxSettings, thrownError){
openErrorWindow(jqXHR.responseText);
console.log(jqXHR);
});
//Handle document Error - example - function undefined
window.onerror = function(e) {
openErrorWindow(e);
console.log(e);
};
//Open new window with error message
function openErrorWindow(message){
var newwindow = window.open('');
newwindow.document.writeln('<title>Console Error</title>');
newwindow.document.writeln(message);
}
您可以覆盖console.log:
var oldlog = console.log
// or console.oldlog = console.log
console.log = function() {
alert(JSON.stringify(arguments))
}
这是一个可以开始的简单示例。
也许您还想覆盖其他控制台功能,例如console.error
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.