Last active
November 8, 2016 13:45
-
-
Save johnwargo/4a9e2b7f963c3d94e7e212fb6a7bc7bc to your computer and use it in GitHub Desktop.
JavaScript window.onerror
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onerror = function (msg, url, line) { | |
var idx = url.lastIndexOf("/"); | |
if (idx > -1) { | |
url = url.substring(idx + 1); | |
} | |
//Build the message string we'll display to the user | |
var errStr = "ERROR in " + url + " (line #" + line + "): " + msg; | |
//Write the error to the console | |
console.error(errStr); | |
//Tell the user what happened | |
alert(errStr); | |
return false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment