And*_*ech 87
检查console
对象(仅使用Firebug创建),如下所示:
if (window.console && window.console.firebug) {
//Firebug is enabled
}
Run Code Online (Sandbox Code Playgroud)
Firebug开发人员决定删除window.console.firebug
.您仍然可以通过检测萤火虫的存在鸭打字像
if (window.console && (window.console.firebug || window.console.exception)) {
//Firebug is enabled
}
Run Code Online (Sandbox Code Playgroud)
或各种其他方法等
if (document.getUserData('firebug-Token')) ...
if (console.log.toString().indexOf('apply') != -1) ...
if (typeof console.assert(1) == 'string') ...
Run Code Online (Sandbox Code Playgroud)
但总的来说,没有必要实际这样做.
自Firebug 1.9.0版起,console.firebug
由于隐私问题,不再定义; 请参阅发行说明,错误报告.这打破了上述方法.实际上,它将艾伦问题的答案改为"没有办法"; 如果是另一种方式,它被认为是一个错误.
相反,解决方案是检查console.log
您要使用或替换的可用性或其他内容.
这里有一个建议,可以替换上面提到的David Brockman所提供的代码,但不会删除任何现有功能.
(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() {};
}
}
})();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13936 次 |
最近记录: |