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

Written by . Filed under JavaScript. Tagged , , , , , , , , , , , . Bookmark the Permalink. Post a Comment. Leave a Trackback URL.
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

One Comment

  1. Posted November 26, 2012 at 4:31 pm | Permalink

    You’ve just saved my day !

    I was wondering why my HTML5 app worked fine on every platforms except WindowsPhone

    Thanks a lot, it did the trick;)

One Trackback

Post a Comment

Your email is never published nor shared.

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>