Last active
August 29, 2015 14:14
-
-
Save carlcraig/37620e942cdf35b3d658 to your computer and use it in GitHub Desktop.
JS Error Catching
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
(function ErrorHandler(errorElement) { | |
var self = this; | |
self.errorcount = 0; | |
self.onerror = onerror; | |
self.originalOnerror = window.onerror; | |
self.revertErrorHandler = revertErrorHandler; | |
window.onerror = self.onerror; | |
window.onload = onload; | |
function onload() { | |
revertErrorHandler(); | |
if (self.errorcount > 0) { | |
document.getElementById(errorElement).style.display = 'block' | |
} | |
} | |
function onerror(msg, url, line, col, error) { | |
self.errorcount++; | |
return false; | |
} | |
function revertErrorHandler() { | |
window.onerror = self.originalOnerror; | |
} | |
})('unsupported-browser'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment