-1

Hi i found the problem in other stackoverflow questions , the problem is i have tried all solutions that should work, but i think im not understanding where and how to implement that fixes..

My problem is console.log in internet explorer throws an error as undefined. I search and found

Console undefined issue in IE8 Internet Explorer: "console is not defined" Error

I try to wrap the code inside the function using a condition like 'if(window.console) '

this dosent work i even try most of the recommended contitions no one work, try to insert the snnipet in the code so it worked, but it dont..

Im obviously not understanding how and where to put does fixes. Sorry for my ignorance. but im in a hurry, need to someone points at my stupidity

Thanks

var jcount = 0;
var scroll_count = 0;   
var playflag=1;
var ajxcallimiter=0;
var hp_totalcount=parseInt($("#hp_totalcount").val());  
if(hp_totalcount<5)
hp_totalcount=5;


function hlist_slider()
{

    if($(".items img").eq(jcount).length != 0 && playflag==1){          
        firedstyle();
        console.log(jcount);
        $(".items img").eq(jcount).trigger("mouseover");

        if(jcount % 5 === 0 && jcount!=0)
        {               
            console.log('scroll');    
            api.next();
            scroll_count++;
        }
        jcount++; // add to the counter     

        if(jcount>hp_totalcount)
        {
             if(playflag==1)
            {               
                jcount = 0; //reset counter
                while(scroll_count--)
                {
                  api.prev();
                }scroll_count=1;
            }
        }

    }
    else if(jcount<hp_totalcount && playflag==1)
    {
        playflag=0;homepagelist_nextclick();playflag=1;
    }
    else
    {
        if(playflag==1)
        {
            jcount = 0; //reset counter
           while(scroll_count--)
            {              
                api.prev();
            }
           scroll_count=1;
        }
    }

}

$(function() {
    var root = $(".scrollable").scrollable({circular: false}).autoscroll({ autoplay: true });
    hlist_slider();
    setInterval(hlist_slider,10000);        
    // provide scrollable API for the action buttons
    window.api = root.data("scrollable");

    });

function firedstyle()
{
$(".items img").on("hover",function() {
    // see if same thumb is being clicked
    if ($(this).hasClass("active")) { return; }

    // calclulate large image's URL based on the thumbnail URL (flickr specific)
    var url = $(this).attr("src").replace("t_", "");
    var tbtit = $(this).siblings('.tbtit').text();
    var tbdesc = $(this).siblings('.tbdescp').text();
    var tbtitgoto = $(this).attr("data");

    // get handle to element that wraps the image and make it semi-transparent
    var wrap = $("#image_wrap").stop(true, true).fadeTo("medium", 0.5);

    // the large image from www.flickr.com
    var img = new Image();


    // call this function after it's loaded
    img.onload = function() {

        // make wrapper fully visible
        wrap.fadeTo("fast", 1);

        // change the image
        wrap.find("img").attr("src", url);
        wrap.find(".img-info h4").text(tbtit);
        wrap.find(".img-info p").text( tbdesc);
        wrap.find("a").attr("href", tbtitgoto);

    };

    // begin loading the image from www.flickr.com
    img.src = url;

    // activate item
    $(".items img").removeClass("active");
    $(this).addClass("active");

// when page loads simulate a "click" on the first image
}).filter(":first").trigger("mouseover");

}

    function toggle(el){
        if(el.className!="play")
        {
            playflag=0;
            el.className="play";
             el.src='images/play.png';

            //api.pause();
        }
        else if(el.className=="play")
        {
            playflag=1;
            el.className="pause";
             el.src='images/pause.png';
           // api.play();
        }

        return false;
    }

    function hp_nxtclick()
    {
           homepagelist_nextclick();
            console.log('scroll');             
             if(api.next()){ 
             scroll_count++;}
    }

function homepagelist_nextclick()
{
    var hp_totalcount=parseInt($("#hp_totalcount").val());  
    var hp_count=parseInt($("#hp_count").val());

    if(hp_totalcount==0 || hp_count >=hp_totalcount)
        return ;

if(ajxcallimiter==1)
    return;
else
    ajxcallimiter=1;

    $.ajax(
            {
                type: "GET",
                url: "<?php echo $makeurl."index/homepageslide/";?>"+hp_count,
                success: function(msg)
                    {
                    hp_count=parseInt($("#hp_count").val())+parseInt(5);
                    $("#hp_count").val(hp_count);

                      $("#hp_list").append(msg);ajxcallimiter=0;                    
                    }
            });

}
Community
  • 1
  • 1
Moncho Chavez
  • 694
  • 2
  • 10
  • 31
  • http://stackoverflow.com/a/17104717/218196 seems to be pretty clear about what to do. Wherever you use `console.log`, do this check first. Since that's cumbersome, you can just define a `console` object with an empty `log` method. – Felix Kling May 09 '14 at 15:41

3 Answers3

3

The problem is that the console (developer tool panel) needs to be active on page-load*.

Hit F12, reload your page, and you should get what you're looking for.

*Just to clarify: The developer panel needs to be open prior to window.console being called/tested. I'm assuming your code is being run on-load.

Matt
  • 3,079
  • 4
  • 30
  • 36
  • I have pressing F12 all day, and clearing cache, and testing... f12 in internet explorer opens the console to inspect elements actually, I think im not understanding what you mean – Moncho Chavez May 09 '14 at 15:47
  • F12 opens up the developer tool. Within the developer tool is the `Script` tab, and within this tab the console is available. How else are you accessing the console? – Matt May 09 '14 at 15:52
1

In my code, I put this snippet at the top - before any other javascript that might try to use the console loads:

if (window.console == null) {
  window.console = {
    log: function() {},
    warn: function() {},
    info: function() {},
    error: function() {}
  };
}

Or in coffeescript:

if not window.console?
  window.console = {
    log: () ->
    warn: () ->
    info: () ->
    error: () ->
  }

This provides a dummy console for browsers that don't include one.

Julian
  • 2,814
  • 21
  • 31
  • Thanks Julian , the first snnipet should be inside function hlist_slider() or outside? i mean before?? – Moncho Chavez May 09 '14 at 15:48
  • @MonchoChavez: Best place for it would be right at the start of your js block - or anywhere that's loaded on every page load. Basically the same as Matt's answer, but a bit more complete. – Julian May 13 '14 at 21:05
1

This should work:

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

This way you will be able to use console.log without producing errors.

Oriol
  • 274,082
  • 63
  • 437
  • 513
  • Thanks should i place this inside function hlist_slider() or before function hlist_slider(), thanks! – Moncho Chavez May 09 '14 at 15:49
  • Place it before any call to `console.log`. It doesn't matter if you use it inside the function, but note then it will run each time you call the function, which is unnecessary. – Oriol May 09 '14 at 15:49
  • Thanks that did it, and my error was the snnipet should be at the top outside and before all functions. i think. thanks – Moncho Chavez May 09 '14 at 15:51