我正在尝试将通常出现在 javascript 控制台中的任何内容发送到我自己的自定义函数。
我试过以下方法
window.console.error = window.console.debug = window.console.log
window.console.log=mylog;
function mylog(msg){
//send it somewhere just using alert as an example
alert("log="+msg);
}
console.log("yo");
var x=y;//a syntax error
使用上面的代码我只看到以下警告 “哟”
在控制台日志中我看到
“x 未定义”
如何重定向语法错误?
最佳答案
您可以使用 onerror
它旨在捕获语法错误。
window.onerror = function(message, source, lineno, colno, error) {
alert(message);
}
关于javascript - 将 Javascript 语法错误和 console.log 重定向到其他地方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35759269/