Javascript that detects Firebug?

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

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

7条回答
  •  悲&欢浪女
    2020-11-27 13:35

    Original answer:

    Check for the console object (created only with Firebug), like such:

    if (window.console && window.console.firebug) {
      //Firebug is enabled
    }
    

    Update (January 2012):

    The Firebug developers have decided to remove window.console.firebug. You can still detect the presence of Firebug by duck typing like

    if (window.console && (window.console.firebug || window.console.exception)) {
      //Firebug is enabled
    }
    

    or various other approaches like

    if (document.getUserData('firebug-Token')) ...
    if (console.log.toString().indexOf('apply') != -1) ...
    if (typeof console.assert(1) == 'string') ...
    

    but in general, there should be no need to actually do so.

提交回复
热议问题