Skip to main content

JavaScript errors in Internet Explorer when dev console is closed

A while back I stumbled upon JavaScript errors that only occurred in IE. I figured out that when the dev console was closed the error occurred, but while it was open it worked perfectly. After some research I discovered that when the dev console is closed in IE, the console is undefined. I defined some default methods for console in case it was undefined to resolve the issue and place the code snippet below as the first lines in $(document).ready(function () {}); of a general JavaScript file that we use in every page of this project.


if(typeof console === 'undefined') {
  console = {
    log : function(){},
    warn: function(){},
    error: function(){},
    time: function(){},
    timeEnd: function(){}