Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
150
rated 0 times [  155] [ 5]  / answers: 1 / hits: 23100  / 13 Years ago, mon, march 21, 2011, 12:00:00

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?


More From » extjs

 Answers
23

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;
};
}

[#93169] Friday, March 18, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lelasamiraa

Total Points: 208
Total Questions: 99
Total Answers: 107

Location: Uzbekistan
Member since Tue, Nov 30, 2021
2 Years ago
;