gpt4 book ai didi

javascript - ExtJs4 + IE9 = 对象不支持属性或方法 'createContextualFragment'

转载 作者:可可西里 更新时间:2023-11-01 02:14:17 25 4
gpt4 key购买 nike

我在 IE9 上使用 ExtJs.. 我几乎总是遇到这个错误..

Microsoft JScript runtime error:

Object doesn't support property or method 'createContextualFragment'

这意味着什么?需要什么“createContextualFragment”?以及如何解决这个问题?

最佳答案

createContextualFragment()Range 对象的一种方法,它从 HTML 字符串创建文档片段。它存在于 Firefox 和 WebKit 和 Opera 中,但目前是非标准的(它不在 DOM Level 2 Range spec 中,但在进行中 DOM Parsing and Serialization spec 中)并且 IE 9 没有实现它,这与微软的一般在 IE 9 中实现以前在 IE 中缺失的标准功能的方法。 ExtJs 必须使用这种方法,虽然相当愚蠢,因为它是非标准的,并且可以使用到处都支持的 innerHTML 轻松实现相同的结果。

更新

您可以将以下内容修补到 IE 9 中,因为它允许扩展主机对象原型(prototype),而以前的版本则不允许。以下是改编 self 的 Rangy librarycreateContextualFragment() 的简单实现但适用于大多数用途。参见 this Rangy issue有关详细信息和更彻底的实现。

请注意,这在 IE < 9 中不起作用,因为这些浏览器没有 DOM Range 实现。

if (typeof Range.prototype.createContextualFragment == "undefined") {
Range.prototype.createContextualFragment = function(html) {
var startNode = this.startContainer;
var doc = startNode.nodeType == 9 ? startNode : startNode.ownerDocument;
var container = doc.createElement("div");
container.innerHTML = html;
var frag = doc.createDocumentFragment(), n;
while ( (n = container.firstChild) ) {
frag.appendChild(n);
}
return frag;
};
}

关于javascript - ExtJs4 + IE9 = 对象不支持属性或方法 'createContextualFragment',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5375616/

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