-5

I made this jQuery script for selecting a color in proces that I made. Now I am testing my script in IE8 and I cannot select colors there anymore.

IE gave me an error that says: 'console is undefined'.

It says the problem is on line 101 in my script and that's this line:

console.log(num);

I founded other articles on stackoverflow (for example this one: 'console' is undefined error for Internet Explorer) that describing and fixing this problem, but I cannot get it work.

Can someone help me with this?

My script:

// Custom Select box
enableSelectBoxes();

// Custom select box function
function enableSelectBoxes(){
    $('div#color_scheme').each(function(){
        if($(this).children('span.selected').html() == '')
            $(this).children('span.selected').html($(this).children('div#colors').children('div#colors span:first').html());

        $(this).find('#colors span').click(function() {

            var num = $(this).data('selnum');

            if (!num) {
                num = $.trim($(this).html());
                console.log(num);
                $(this).data('selnum', num);
            }

            var oldSel = $('#colors span.selected_color');
            oldSel.removeClass('selected_color').empty().html(oldSel.data('selnum'));

            //remember the bg color
            var bgColor = $(this).css('background');

            if($(this).hasClass('color_none')) {
                $(this).addClass('selected_color').html(
                num + '<div class="this_color"><div class="color_example">Color value</div><input type="submit" name="submit_color" value="Selecteer"/></div>');
            }
            else {
                $(this).addClass('selected_color').html(
                num + '<div class="this_color"><div class="color_example">Color value</div><input type="submit" name="submit_color" value="Selecteer kleur"/></div>');
            }

            $('[name=submit_color]').click(function(e) { e.stopPropagation(); });

            $(".color_example").html($(this).attr('value'));

            //set the bgColor
            $(".color_example").css({
                background : bgColor
            });

            $("#color_field").attr('value',$(this).attr('value'));

        });
    }); 
}   
Community
  • 1
  • 1
Robbert
  • 1,270
  • 6
  • 30
  • 62
  • 2
    Basically, you have to open your console in IE8 or use any shim to handle it: `if(!window.console) window.console = {log:$.noop}` – A. Wolff Dec 23 '13 at 11:17
  • 1
    Why did the solution given in the other question not work? You don't have it anywhere in the code. – JJJ Dec 23 '13 at 11:18
  • IE8/9 do not define the `console` object unless/until Dev tools window is opened. See the dups for more info. – Spudley Dec 23 '13 at 11:20
  • @Juhana I putted the if (!window.console) console = {log: function() {}}; in my header – Robbert Dec 23 '13 at 12:05

1 Answers1

3

Just add this to the top of your script:

if (!window.console) console = {log: function() {}};

Let me know if you still have problems.

Selven
  • 276
  • 4
  • 12
  • I placed the code at the top, and now there is nog error window anymore but my code doesn't work. Normally when I click on a color my scripts ensures that the color popups and then you can submit/click on it. But when I click now on a color nothing is happening. So I think I need to do something with my script? – Robbert Dec 23 '13 at 12:08