Created
February 7, 2017 13:43
-
-
Save alireza-saberi/e266197c5246df513200096cee714cb5 to your computer and use it in GitHub Desktop.
console.log solution for IE9 (2011) and earlier browsers.
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
| /* | |
| Jan-7th-2017 | |
| http://caniuse.com/#feat=console-basic | |
| IE9: Only supports console functions when developer tools are open, otherwise the console object is undefined and any calls will throw errors. | |
| IE 11 mobile, UC browser, Blackberry browsers, Opera 37 for Anroid | |
| Allows console functions to be used without throwing errors, but does not appear to output the data anywhere | |
| */ | |
| // solution 1: Wrapper function | |
| function log(text) { | |
| if (window.console) { | |
| window.console.log(text); | |
| } | |
| } | |
| // solution 2: Check to see if the function exists and create a dummy in case it does not | |
| if (!window.console) window.console = {}; | |
| if (!window.console.log) window.console.log = function () { }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment