ExtJs4 + IE9 = Object不支持属性或方法'createContextualFragment' [英] ExtJs4 + IE9 = Object doesn't support property or method 'createContextualFragment'
问题描述
Microsoft JScript运行时错误:
我正在使用IE9上的ExtJs ..我几乎总是得到这个错误。 / p>
对象不支持属性或
方法'createContextualFragment'
这意味着什么剂量?需要什么'createContextualFragment'?如何解决这个问题?
createContextualFragment()
是一种 Range
创建的对象的方法来自HTML字符串的文档片段。它存在于Firefox和WebKit和Opera中,但目前是非标准的(它不在 DOM Level 2 Range spec ,但正在进行中的工作中 DOM解析和序列化规范)和IE 9没有实现它,这与Microsoft以前在IE中缺少的IE 9中实现标准功能的一般方法是一致的。 ExtJs必须使用这种方法,虽然是非常愚蠢的,因为它是非标准的,并且使用
innerHTML
可以很容易地实现相同的结果。 b $ b
更新
您可以将以下内容修补到IE 9中,因为它允许扩展主机对象原型,以前的版本没有。以下是从我的 Rangy库 c>中修改的 createContextualFragment()
/ a>,但适用于大多数用途。有关详细信息,请参见此Rangy问题。
请注意,这不会在IE< 9,因为这些浏览器没有DOM范围的实现。
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;
};
}
I'm working with ExtJs on IE9.. and i almost always get this error..
Microsoft JScript runtime error:
Object doesn't support property or method 'createContextualFragment'
What dose it means? What 'createContextualFragment' is needed for? And how to fix this?
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.
UPDATE
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.
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 = Object不支持属性或方法'createContextualFragment'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!