After the firebug panel is enabled, a window.console object and window.console.firebug variable will be added to save the current version of the current firebug. When the firebug panel is closed, it will return to normal, so we can detect it by judging whether it exists. Whether firebug is enabled.
Boolean(window.console && window.console.firebug)
So, in order to avoid script errors when firebug is not enabled, you can add the following statement at the beginning of the script to manually create an empty console object for compatibility.
if (!window.console) {
/ / ignore firebug console call if it's not installed
// for firebug 1.6.0
(function(m, i) {
window.console = {};
while (i--) {
window.console[m[i]] = function() {};
}
})('log debug info warn exception assert dir dirxml trace group groupEnd groupCollapsed time timeEnd profile profileEnd count clear table error notifyFirebug'.split(' '), 22);
}
In this way, the page can be previewed normally under IE, and debugging information can also be output normally in Firefox, Chrome, and Safari.