What happened to console.log in IE8?

后端 未结 17 2516
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 04:45

According to this post it was in the beta, but it\'s not in the release?

相关标签:
17条回答
  • 2020-11-22 05:24

    It's worth noting that console.log in IE8 isn't a true Javascript function. It doesn't support the apply or call methods.

    0 讨论(0)
  • 2020-11-22 05:26

    console.log is only available after you have opened the Developer Tools (F12 to toggle it open and closed). Funny thing is that after you've opened it, you can close it, then still post to it via console.log calls, and those will be seen when you reopen it. I'm thinking that is a bug of sorts, and may be fixed, but we shall see.

    I'll probably just use something like this:

    function trace(s) {
      if ('console' in self && 'log' in console) console.log(s)
      // the line below you might want to comment out, so it dies silent
      // but nice for seeing when the console is available or not.
      else alert(s)
    }
    

    and even simpler:

    function trace(s) {
      try { console.log(s) } catch (e) { alert(s) }
    }
    
    0 讨论(0)
  • 2020-11-22 05:28

    Here is my "IE please don't crash"

    typeof console=="undefined"&&(console={});typeof console.log=="undefined"&&(console.log=function(){});
    
    0 讨论(0)
  • 2020-11-22 05:28

    Make your own console in html .... ;-) This can be imprved but you can start with :

    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);
            }
        };
    }
    
    0 讨论(0)
  • 2020-11-22 05:30

    Here is a version that will log to the console when the developer tools are open and not when they are closed.

    (function(window) {
    
       var console = {};
       console.log = function() {
          if (window.console && (typeof window.console.log === 'function' || typeof window.console.log === 'object')) {
             window.console.log.apply(window, arguments);
          }
       }
    
       // Rest of your application here
    
    })(window)
    
    0 讨论(0)
  • 2020-11-22 05:36
    if (window.console && 'function' === typeof window.console.log) {
        window.console.log(o);
    }
    
    0 讨论(0)
提交回复
热议问题