Javascript that detects Firebug?

前端 未结 7 1925
抹茶落季
抹茶落季 2020-11-27 12:47

What\'s a surefire way of detecting whether a user has Firebug enabled?

7条回答
  •  无人及你
    2020-11-27 13:21

    As of Firebug version 1.9.0, console.firebug is no longer defined because of privacy concerns; see release notes, bug report. This breaks the above mentioned methods. Indeed, it changes the answer to Allan's question to "there is no way"; if there is another way, it's considered a bug.

    The solution instead is to check for the availability of console.log or whatever it is you want to use or replace.

    Here is a suggestion for a replacement for the kind of code that David Brockman is presenting above, but one that doesn't remove any existing functions.

    (function () {
        var names = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml', 
                    'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd'];
    
        if (window.console) {
            for (var i = 0; i < names.length; i++) {
                if (!window.console[names[i]]) {
                    window.console[names[i]] = function() {};
                }
            }
        } else {
            window.console = {};
            for (var i = 0; i < names.length; i++) {
                window.console[names[i]] = function() {};
            }
        }
    })();
    

提交回复
热议问题