gpt4 book ai didi

javascript - 改变 firebugx.js 以适应 IE 开发者工具

转载 作者:数据小太阳 更新时间:2023-10-29 04:44:56 26 4
gpt4 key购买 nike

firebugx.js文件(如下所示)同时检查 !window.console 和 !console.firebug,它可以正确检测是否安装了 firebug。但是,该检查不适应 IE 开发人员工具中的 native 控制台对象——它会覆盖 IE 控制台对象。

例如,如果我包含 firebugx.js 代码,那么以下异常将不会出现在 IE 控制台中(它会被吞掉):

  function foo() {
try {
throw "exception!!!";
}
catch (e) {
console.error(e);
}
}

问题:容纳 IE 开发人员调试器的最佳方法是什么?也许显而易见的答案是在 IE 中调试时简单地注释掉 firebugx.js 检查。还有其他方法吗?

引用:

firebugx.js

if (!window.console || !console.firebug)
{
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

window.console = {};
for (var i = 0; i < names.length; ++i)
window.console[names[i]] = function() {}
}

最佳答案

我想对 firebugx.js 进行以下修改可以解决问题。我只在 window.console 不存在时才重新定义它,然后选择性地在 window.console 上定义缺少的函数。我对更改 firebugx.js 犹豫不决,但我真的看不出这有什么缺点。这是在 Firefox 和 IE 调试器之间快速切换的最简单方法。

firebugxCustom.js

if (!window.console) {
window.console = {};
}
if (!window.console.firebug) {
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

for (var i = 0; i < names.length; ++i) {
if (!window.console[names[i]]) {
window.console[names[i]] = function () { }
}
}
}

关于javascript - 改变 firebugx.js 以适应 IE 开发者工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4901196/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com