Skip to content

Instantly share code, notes, and snippets.

@alireza-saberi
Created February 7, 2017 13:43
Show Gist options
  • Select an option

  • Save alireza-saberi/e266197c5246df513200096cee714cb5 to your computer and use it in GitHub Desktop.

Select an option

Save alireza-saberi/e266197c5246df513200096cee714cb5 to your computer and use it in GitHub Desktop.
console.log solution for IE9 (2011) and earlier browsers.
/*
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