JS: Prevent IE crash when using console (console.log)

console is undefined
console is undefined

When the console is close and we call console.log from javascript most of the times
Internet Explorer will crash with the message:
Error: ‘console’ is undefined

Here is my solution for this annoying bug.

if (typeof console == 'undefined')   {
	var console = new Object();
	console.log = function(){}
	console.error = function(){}
	console.debug = function(){}
	console.warn = function(){}

Thanks “brucebannor” for advice.

Have fun :)
Garry Lachman

2 thoughts on “JS: Prevent IE crash when using console (console.log)

Leave a Reply

Your email address will not be published. Required fields are marked *


Protected with SiteGuarding.com Antivirus