Problem: ‘Console’ is undefined Error

Great, a new JavaScript problem. Better yet, a new Internet Explorer AND Firefox problem.

So I ran into this error while ensuring a site was great on all browsers. Of course, everything else was finally fine, but here's a new problem.

See that mess? Eww. I didn't want some silly old error there, besides the fact that this error cancelled out the animated functiions I needed the page to run. After extensive Google perusing, I found naught. This is an error I'm getting from a JavaScript file in my WordPress setup. I found the error:

if (o.debug) console.log('ss-slider-' + $parent[0].id + ': type slide set. Fixed height set: ' + item_height);

So looking into this error more closely (and being less lazy. There's more to the file.) I figured out that this error means IE and Firefox are looking for console, but the console only shows for those browsers when you have the developer console or Firebug console open already. And what elderly person visiting the website is going to have Firebug? None.

To get to the point, here's the fix, in fact two. 

Solution 1

Comment out the console.log call. It doesn't really need to be there for other users.

Solution 2

Found this solution from commenting out things is bad, especially if the file is not something that you made yourself. The function in the file could have a real purpose. How about we cancel it out by adding code?

// Begin console error fix for IE8 and Firefox 3.6.28
			if(typeof(console) === 'undefined') {
   			var console = {}
    			console.log = console.error = = console.debug = console.warn = console.trace = console.dir = console.dirxml = = console.groupEnd = console.time = console.timeEnd = console.assert = console.profile = function() {};
			// End console error fix for IE8 and Firefox 3.6.28

And there you have it, make sure this code is above the line that is bothering your site, in a separate clean code block. Let me know if this works, or just ask the guy!

Comments are now closed for this entry


Visit Betfair Review