Home >Web Front-end >JS Tutorial >What Happened to console.log in IE8?
What happened to console.log in IE8?
Developers had expected to see the console.log method in the beta version of IE8, but it was nowhere to be found in the official version. So, what exactly happened?
Answer:
console.log is actually only available after opening the developer tools, press F12 to turn this tool on or off. Interestingly, after opening the Developer Tools and even if you close it, you can still write content to it via console.log calls, which will appear the next time you reopen the tool.
Siege Lions speculate that this is a bug that may be fixed in a later version, but this has not been confirmed yet.
Solution:
Consider using one of the following functions:
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) }
Easier way of writing:
function trace(s) { try { console.log(s) } catch (e) { alert(s) } }
The above is the detailed content of What Happened to console.log in IE8?. For more information, please follow other related articles on the PHP Chinese website!