Javascript Console.log Internet explorer 8特殊情况

Javascript Console.log Internet explorer 8特殊情况,javascript,Javascript,您好,我在其他stackoverflow问题中发现了问题,问题是我已经尝试了所有应该有效的解决方案,但我认为我不了解在何处以及如何实施修复 我的问题是internet explorer中的console.log会抛出一个未定义的错误。我搜索并找到了 我尝试使用类似“if(window.console)”的条件将代码包装到函数中 这项工作我甚至尝试了大多数推荐的Conditions没有人工作,尝试在代码中插入snnipet使其工作,但它不 很明显,我不知道该怎么做,该放在哪里。对不起我的无知。

您好,我在其他stackoverflow问题中发现了问题,问题是我已经尝试了所有应该有效的解决方案,但我认为我不了解在何处以及如何实施修复

我的问题是internet explorer中的console.log会抛出一个未定义的错误。我搜索并找到了

我尝试使用类似“if(window.console)”的条件将代码包装到函数中

这项工作我甚至尝试了大多数推荐的Conditions没有人工作,尝试在代码中插入snnipet使其工作,但它不

很明显,我不知道该怎么做,该放在哪里。对不起我的无知。但是我很忙,需要有人指出我的愚蠢

谢谢

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;                    
                    }
            });

}
var jcount=0;
var\u计数=0;
var playflag=1;
var ajxcalimiter=0;
var hp_totalcount=parseInt($(“#hp_totalcount”).val();
if(hp_totalcounthp_totalcount)
{
如果(播放标志==1)
{               
jcount=0;//重置计数器
while(滚动\u计数--)
{
api.prev();
}滚动计数=1;
}
}
}
else if(jcount=hp\u totalcount)
返回;
如果(AjxCalimiter==1)
返回;
其他的
AjxCalimiter=1;
$.ajax(
{
键入:“获取”,
url:“+hp\U计数,
成功:功能(msg)
{
hp#u count=parseInt($(“#hp#u count”).val()+parseInt(5);
$(“hp#U计数”).val(hp#U计数);
$(“#hp_列表”).append(msg);ajxcalimiter=0;
}
});
}

问题在于控制台(开发人员工具面板)需要在页面加载时处于活动状态*

点击F12,重新加载你的页面,你就会得到你想要的


*仅澄清一下:在调用/测试
窗口.控制台
之前,需要打开开发人员面板。我假设您的代码是在加载状态下运行的。

在我的代码中,我将此代码段放在顶部-在尝试使用控制台加载的任何其他javascript之前:

if (window.console == null) {
  window.console = {
    log: function() {},
    warn: function() {},
    info: function() {},
    error: function() {}
  };
}
或者用咖啡脚本:

if not window.console?
  window.console = {
    log: () ->
    warn: () ->
    info: () ->
    error: () ->
  }
这为不包含虚拟控制台的浏览器提供了虚拟控制台。

这应该可以:

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

通过这种方式,您将能够使用console.log而不会产生错误。

似乎非常清楚该怎么做。无论您在何处使用
console.log
,请先执行此检查。因为这很麻烦,你可以用一个空的
log
方法定义一个
console
对象。。。internet explorer中的f12打开控制台检查元素实际上,我想我不明白你的意思f12打开开发工具。开发者工具中有
脚本
选项卡,在该选项卡中可以使用控制台。您还要如何访问控制台?谢谢Julian,第一个snnipet应该在函数hlist_slider()内部还是外部?我的意思是在之前???@MonchoChavez:最好的地方是在js块的开始处,或者在每次加载页面时加载的任何地方。基本上与Matt的答案相同,但更完整一点。谢谢我应该将此放在函数hlist_slider()内还是放在函数hlist_slider()之前,谢谢!将其放在调用
控制台.log
之前。如果你在函数内部使用它并不重要,但是请注意,每次调用函数时它都会运行,这是不必要的。谢谢你这么做了,我的错误是snnipet应该在所有函数之外的顶部。我想。谢谢