对象不支持此属性或方法。

4

将GWT版本升级到2.5.0后,当我悬停在图表(SVG)上时,出现了问题。

该问题仅在IE中出现(Chrome和Firefox不受影响)。

错误信息为:

捕获到2个异常:(TypeError) 描述:对象不支持属性或方法“contains” 数字:-2146827850: 对象不支持属性或方法“contains”;

该问题似乎是由DOMImplTrident类中的一个新方法isOrHasChildImpl引起的。

我想知道是否有其他人遇到过此问题或者是否知道其他解决方法,除了不使用IE ;)

谢谢!


有特定的IE版本吗? - Hilbrand Bouwkamp
你可以使用详细模式进行编译,并在应用程序中添加异常处理程序并打印堆栈跟踪,以查看问题的来源。 - Thibault D.
我正在使用IE 9版本。它在8版本中可以工作。 - Lt_Shade
1个回答

3
我猜测您的问题可能来自DOMImplTrident.isOrHasChildImpl方法的第53行。
return (parent === child) || parent.contains(child);

我猜测你遇到的错误是在IE10上出现的?我认为你是在IE10上运行,原因是GWT不支持使用单独的DOM实现来处理IE10。它最终会在IE10上使用DOMImplIE9实现,该实现会使用DOMImplTrident中的以上方法来实现'isOrHasChild'。我想知道第47行是否

if (parent.nodeType == 9) {

对于文档节点,实际上没有返回9,因此会进入“else”语句并在尝试访问“contains”方法时崩溃。也许IE10不像之前的IE版本一样实现这些节点方法?不确定。

我手头没有IE10来测试这个理论,但这可能是一个好的起点。您可以创建自己的JSNI方法,进行类似的节点调用以测试该理论,并查看“document.nodeType”是否确实返回9,或者“node.contains”是否在各种类型的节点上崩溃。

如果确实是这个问题,您可以尝试一些方法来修复/避免问题。

  1. Try hooking up an GWT.setUncaughtExceptionHandler() in your entry point and just ignore the error altogether.

  2. Stick a try/catch around the block of code in one of 'your' methods that is invoking the problem code and ignore the exception.

  3. Try adding the following meta tag to your html file and see if rendering in IE10 as IE9 solves the problem.

    <meta http-equiv="X-UA-Compatible" content="IE=9" />
    
  4. Create a custom DOMImpl that extends DOMImplIE9 and overrides the 'isOrHasChild' method with your own custom method where you have control over what happens. For example

    package com.google.gwt.dom.client;
    
    public class DOMImplIE9Custom extends DOMImplIE9 {
        @Override
        public boolean isOrHasChild(Node parent, Node child) {
            // Do your own thing
        }
    }
    
然后,您可以使用延迟绑定来切换DOMImplIE9与您的自定义实现,如下所示:
<replace-with class="com.google.gwt.dom.client.DOMImplIE9Custom">
    <when-type-is class="com.google.gwt.dom.client.DOMImpl"/>
    <when-property-is name="user.agent" value="ie9"/>
</replace-with>

即使我离谷底很远,而且您没有使用IE10,您仍然可以尝试上述方法来解决问题。或者,进行终极修复,停止使用IE,并避免多个小时的压力。希望这能帮助您找到正确的解决方案。

GWT.setUncaughtExceptionHandler()已经捕获了异常,看起来它会很好地完成任务。谢谢。 - Lt_Shade

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接