How to use window. onerror to capture and report Js errors _ javascript skills

Source: Internet
Author: User
This article mainly introduces window. onerror: the method for capturing and reporting Js errors. if you need a friend, refer to a 2048 game user feedback in the next two days. after opening the game, you cannot play. there is only one game panel, and the number cannot be initialized, even more mobile, the device is iPhone 4 S, iOS 5.1. It is still difficult to enable Safari from startup. Because the game uses a lot of HTML5 features, it is roughly estimated that JS errors are caused. But how can this information be captured? Of course it is the legendary window. onerror.

Find the method body for window. onerror from W3C:

This means that the window. onerror method can be written as follows:

/*** @ Param {String} errorMessage error message * @ param {String} scriptURI error file * @ param {Long} lineNumber error code line number * @ param {Long} columnNumber error code column number * @ param {Object} errorObj error details, anything */window. onerror = function (errorMessage, scriptURI, lineNumber, columnNumber, errobj) {// TODO}

However, you must pay attention to compatibility issues during use. not all browsers have all the parameters in the parameter list. chrome and others are the leading browser standard draft. These parameters are used!

Therefore, you can write a small Demo to try it:

     Js error capture   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.