Home > Web Front-end > JS Tutorial > body text

Code to use JavaScript to detect whether Firebug is enabled in Firefox browser_javascript tips

WBOY
Release: 2016-05-16 18:13:06
Original
840 people have browsed it

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.

Copy code The code is as follows:

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.
Copy code The 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 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.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template