After the firebug panel is enabled, a window is added. console object and window. console. the firebug variable is used to save the current version of the current firebug. When the firebug panel is closed, the variable returns to normal. Therefore, we can check whether the firebug is enabled by checking whether it exists.
Copy codeThe Code is as follows: Boolean (window. console & window. console. firebug)
Therefore, to avoid script errors without enabling firebug, you can add the following statement at the beginning of the script to manually create an empty console object for compatibility.Copy codeThe Code is as follows: 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 policyfirebug '. split (''), 22 );
}
In this way, the page can be normally previewed in IE, and debugging information can be normally output in Firefox, Chrome, and Safari.