How to catch javascript exceptions/errors? (To log them on server)

后端 未结 1 470
既然无缘
既然无缘 2021-01-30 09:41

Duplicate:

  • Automatic feedback on JavaScript error
  • Logging JavaScript-Errors on Server

How would I go abou

相关标签:
1条回答
  • 2021-01-30 10:13

    I use this function in all my projects:

    window.onerror = function(m,u,l){
        jQuery.post("ajax/js_error_log.php",
            { msg: m,
              url: u,
             line: l,
           window: window.location.href });
        return true};
    

    Make sure it is the very first javascript the browser receives or at least precedes any potentially error-causing code. Requires jQuery of course, but you could code ajax functions in pure javascript if you wanted to.

    Please note: this will not help you if you have a syntax error. All javascript instantly dies if there is a syntax error.

    0 讨论(0)
提交回复
热议问题