2011-04-12 34 views
3

可能重复:
Javascript that detects Firebug?如何检查Mozilla中是否安装了Firebug?

如何检查萤火虫是否被安装在Mozilla或不使用JavaScript代码?

+0

这取决于你的目的是什么 - 通过fbug登录?然后检查console.log可能就足够了(请注意,还有其他定义console.log的工具)。防止拆卸?那么请不要,并非每个* * * * * * *都试图破坏您的应用程序。 – Piskvor 2011-04-12 11:48:06

+0

ya通过萤火虫登录 – SSN 2011-04-12 11:49:40

回答

2

在网页中的任何地方,你可以这样做:

<script> 
if(console) { 
    console.log("Firebug is installed and running!"); 
} else { 
    alert("Firebus either isn't installed, or isn't running."); 
} 
</script> 

不完美的,如果你特别要检查Firebug的,因为它可能会报告说,萤火虫存在于其他浏览器,如Chrome浏览器,因为它们的开发者工具也使用与Firebug相同的对象console。如果您确实需要检查Firebug,那么您还可以添加浏览器检测以确保您使用的是Firefox。

+0

如果控制台不存在,这将引发异常。 'if(window.console)'或'if(typeof console!=='undefined')'会更好。 – 2011-12-23 14:33:18

2

接受的答案根本没有检测到Firebug,它只是检测一个console对象是否可用。

如果要检测Firebug,请查找window.console.firebug。使用this snippet

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