捕获所有 JavaScript 错误并将它们发送到服务器 [英] Catch all JavaScript errors and send them to server

查看:20
本文介绍了捕获所有 JavaScript 错误并将它们发送到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人在全局处理 JavaScript 错误并将它们从客户端浏览器发送到服务器方面有经验.

I wondered if anyone had experience in handling JavaScript errors globally and send them from the client browser to a server.

我想我的观点很清楚,我想知道客户端发生的每个异常、错误、编译错误等,并将它们发送到服务器报告.

I think my point is quite clear, I want to know every exception, error, compilation error, etc. that happens on the client side and send them to the server to report them.

我主要使用 MooTools 和 head.js(用于 JS 端)和 Django 用于服务器端.

I’m mainly using MooTools and head.js (for the JS side) and Django for the server side.

推荐答案

我会查看 window.onerror

示例:

window.onerror = function(message, url, lineNumber) {  
  //save error and send to server for example.
  return true;
};  

请记住,返回 true 将阻止触发默认处理程序,返回 false 将让默认处理程序运行.

Keep in mind that returning true will prevent the firing of the default handler, and returning false will let the default handler run.

这篇关于捕获所有 JavaScript 错误并将它们发送到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆