2

从运行AJAX应用程序的角度来看,当打开IE Developers Tools时发生了什么变化?

我现在正在追踪一些薛定谔错误。这是关于IE中PrimeFaces下拉列表。它们有时在单击后无法打开,并且在最大化浏览器或取消缩放内容后它们会被“解锁”。因为这些下拉菜单是在正常输入的基础上实现的,并带有附加的 div,所以我认为这是错误地计算了显示下拉菜单的位置。我还假设 AJAX 错误。

但打开 IE Developers Tools 后,几乎不可能重现该错误。控制台中没有显示错误,没有 AJAX 请求挂起,而且,一切似乎都运行得更好。

该错误仅针对IE,因此开发人员工具是调试它的唯一方法。然而,当它们被打开时,似乎观察结果会以某种方式改变状态,就像在量子力学中一样……

所以,我需要知道,通过打开那些开发人员工具可以改变什么,以防止错误出现?

--edit--console.log. 无关。这是计算不可见元素大小的问题。通过向正文添加滚动解决了该问题。然而,问题是开放的,IE 开发者工具是如何影响这些计算的。

4

1 回答 1

1

If you really want to always include using console, I suggest using a polyfill for it:

(function(b){
    var a=0;
    var c=function(){};
    var d=["log","assert","clear","count","debug","dir","dirxml","error","exception","group","groupCollapsed","groupEnd","info","profile","profileEnd","table","time","timeEnd","timeStamp","trace","warn"];
    b.console=b.console||{};
    for(;a<d.length;a++){
        b.console[d[a]]=b.console[d[a]]||b.console["log"]||c;
    }
})(window);

This a minified example that I tried to make readable. It's something I found awhile ago and modified some. I think the main thing I modified is that if you call a method that wasn't originally implemented by the browser's native console, it will call console.log. If console.log wasn't natively implemented, it just calls an empty function. The original version of this code didn't include this fallback to console.log.

This will "guarantee" that console calls will not fail. You can change the d variable to only include calls you are sure you will use, otherwise there's some extra unnecessary processing.

于 2013-01-31T15:29:35.273 回答