ExtJs4 + IE9 = 对象不支持属性或方法“createContextualFragment" [英] ExtJs4 + IE9 = Object doesn't support property or method 'createContextualFragment'
问题描述
我在 IE9 上使用 ExtJs .. 我几乎总是遇到这个错误..
I'm working with ExtJs on IE9.. and i almost always get this error..
Microsoft JScript 运行时错误:
Microsoft JScript runtime error:
对象不支持属性或方法'createContextualFragment'
Object doesn't support property or method 'createContextualFragment'
剂量是什么意思?需要什么createContextualFragment"?以及如何解决这个问题?
推荐答案
createContextualFragment()
是 Range
对象的一种方法,它从 HTML 字符串创建文档片段.它存在于 Firefox、WebKit 和 Opera 中,但目前是非标准的(它不在 DOM 级别 2 范围规范 但正在开发中 DOM 解析和序列化规范) 和 IE 9 没有实现它,这与微软在 IE 9 中实现标准功能的一般方法一致,而以前在 IE 中没有.ExtJs 必须使用这种方法,虽然相当愚蠢,因为它是非标准的,并且可以使用 innerHTML
轻松实现相同的结果,它在任何地方都受支持.
createContextualFragment()
is a method of Range
objects that creates a document fragment from an HTML string. It's present in Firefox and WebKit and Opera but is currently non-standard (it's not in the DOM Level 2 Range spec but is in the work-in-progress DOM Parsing and Serialization spec) and IE 9 didn't implement it, which is consistent with Microsoft's general approach to implementing standard functionality in IE 9 that was previously missing in IE. ExtJs must be using this method, although rather foolishly since it is non-standard and the same result can easily be achieved using innerHTML
, which is supported everywhere.
更新
您可以将以下内容修补到 IE 9 中,因为它允许扩展主机对象原型,而以前的版本则不允许.以下是改编自我的 Rangy 库 的 createContextualFragment()
的简单实现,但适用对于大多数用途.请参阅这个 Rangy 问题了解详情和更彻底的实施.
You can patch the following into IE 9 since it allows extension of host object prototypes, which previous versions did not. The following is a naive implementation of createContextualFragment()
adapted from my Rangy library but is suitable for most uses. See this Rangy issue for details and for a more thorough implementation.
请注意,这在 IE 中不起作用 <9 因为那些浏览器没有 DOM Range 实现.
Note that this will not work in IE < 9 because those browsers have no DOM Range implementation.
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;
};
}
这篇关于ExtJs4 + IE9 = 对象不支持属性或方法“createContextualFragment"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!