在服务器上记录客户端JavaScript错误 [英] Logging Clientside JavaScript Errors on Server
问题描述
是否有可能捕获所有JavaScript错误?客户端,并在服务器上登录,即在EventLog中(通过Webservice或类似的方式)?
您可以尝试设置您自己的 onerror事件的处理程序,并使用XMLHttpRequest告诉服务器出现了什么问题,但是由于它不属于任何规范,因此支持有些片面。
以下是使用XMLHttpRequest记录JavaScript错误:
window.onerror = function(msg,url,line)
{
var req = new XMLHttpRequest();
var params =msg =+ encodeURIComponent(msg)+'& amp; amp; url ='+ encodeURIComponent(url)+& amp; amp;
req.open(POST,/scripts/logerror.php);
req.send(params);
};
Im running a ASP.NET Site where I have problems to find some JavaScript Errors just with manual testing.
Is there a possibility to catch all JavaScript Errors on the Clientside and log them on the Server i.e. in the EventLog (via Webservice or something like that)?
You could try setting up your own handler for the onerror event and use XMLHttpRequest to tell the server what went wrong, however since it's not part of any specification, support is somewhat flaky.
Here's an example from Using XMLHttpRequest to log JavaScript errors:
window.onerror = function(msg, url, line)
{
var req = new XMLHttpRequest();
var params = "msg=" + encodeURIComponent(msg) + '&url=' + encodeURIComponent(url) + "&line=" + line;
req.open("POST", "/scripts/logerror.php");
req.send(params);
};
这篇关于在服务器上记录客户端JavaScript错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!