I want to display script errors in a popup alert instead of showing them in the browser console.
window.onerror = function() {
var message = /* get error messages and put them here */;
alert(message);
return true;
};
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, that is the correct way.
See the reference here:
http://www.javascriptkit.com/javatutors/error2.shtml
And explanation of how to see more details of the error here:
http://www.javascriptkit.com/javatutors/error3.shtml
Their example:
If you wish to display a LIST of errors in a single pop-up, it’s trickier.
Since the errors occue 1 by 1, you need to do the following:
window.onerrorhandler store error details in some arrayCheck that array periodically – either via a timer, or on every N’th call of
window.onerrorhandler, or both.When the check happens, process entire array, display contents as desired, and empty out an array