console.log常因不明原因在IE9出现SCRIPT5009: 'console' is undefined (console未被定义) 错误!
IE9说console变量未定义? 但F12打开控制台后console.log()却又正常!
上图源自:
是不是可以反之证明只有在F12打开控制台时console变量才有效,才能使用console.log()函数.
IE8/9就是渣渣,启动慢还卡,屁事还多!
如果使用环境包含IE8/9,用if (window.console) { ... }包住console.log()函数.
或者可以
window.console = window.console || (function() { var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile = c.clear = c.exception = c.trace = c.assert = function(){}; return c; })();