根据这篇文章,它在测试版中,但它不在发行版中?


当前回答

if (window.console && 'function' === typeof window.console.log) {
    window.console.log(o);
}

其他回答

它适用于IE8。点击F12打开IE8的开发者工具。

>>console.log('test')
LOG: test

假设你不关心提醒的备用方法,这里有一个更简洁的方法来解决ie的缺点:

var console=console||{"log":function(){}};

在html ....中制作自己的控制台: -) 这是可以改进的,但你可以从以下开始:

if (typeof console == "undefined" || typeof console.log === "undefined") {
    var oDiv=document.createElement("div");
    var attr = document.createAttribute('id'); attr.value = 'html-console';
    oDiv.setAttributeNode(attr);


    var style= document.createAttribute('style');
    style.value = "overflow: auto; color: red; position: fixed; bottom:0; background-color: black; height: 200px; width: 100%; filter: alpha(opacity=80);";
    oDiv.setAttributeNode(style);

    var t = document.createElement("h3");
    var tcontent = document.createTextNode('console');
    t.appendChild(tcontent);
    oDiv.appendChild(t);

    document.body.appendChild(oDiv);
    var htmlConsole = document.getElementById('html-console');
    window.console = {
        log: function(message) {
            var p = document.createElement("p");
            var content = document.createTextNode(message.toString());
            p.appendChild(content);
            htmlConsole.appendChild(p);
        }
    };
}
if (window.console && 'function' === typeof window.console.log) {
    window.console.log(o);
}

值得注意的是,IE8中的console.log并不是一个真正的Javascript函数。它不支持apply或call方法。