Created
May 14, 2013 14:40
-
-
Save daviferreira/5576447 to your computer and use it in GitHub Desktop.
console crossbrowser
This file contains hidden or 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
/** | |
* Protect window.console method calls, e.g. console is not defined on IE | |
* unless dev tools are open, and IE doesn't define console.debug | |
*/ | |
(function () { | |
if (!window.console) { | |
window.console = {}; | |
} | |
// union of Chrome, FF, IE, and Safari console methods | |
var functionCall = function () {}, | |
i, | |
m = ['log', 'info', 'warn', 'error', 'debug', 'trace', 'dir', 'group', | |
'groupCollapsed', 'groupEnd', 'time', 'timeEnd', 'profile', 'profileEnd', | |
'dirxml', 'assert', 'count', 'markTimeline', 'timeStamp', 'clear']; | |
// define undefined methods as noops to prevent errors | |
for (i = 0; i < m.length; i += 1) { | |
if (!window.console[m[i]]) { | |
window.console[m[i]] = functionCall; | |
} | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment