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

Written by Garry Lachman (Admin). Filed under JavaScript. Tagged , , , , , , , , , , , . Bookmark the Permalink. Post a Comment. Leave a Trackback URL.

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.

1
2
3
4
5
6
7
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

Share

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

  1. By Blog bookmarks 11/01/2012 « My Diigo bookmarks on November 1, 2012 at 6:32 am

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

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

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>

*