read
Here’s a quick little JavaScript function that allows you to continue your loving relationship with Firebug in Firefox, but also not break your Internet Explorer users. This function wraps the console.log() function and makes sure that it exists before it tries to use it. This avoids causing JavaScript errors in IE.
log = function(msg) {
if ("console" in window) {
console.log(msg);
}
};
To test this create a page with that code that looks something like the code below. Then run it in Firefox and Internet Explorer.
log = function(msg) {
if ("console" in window) {
console.log(msg);
}
};
log("hi!");
Short, but useful, and this can clearly be extended to do many more useful things. It can also easily be changed to check for Firebug Lite in IE, or even just drop down to an alert if necessary. Happy coding!