I was just wondering why createContextualFragment is available in
Mozilla browsers when they also have innerHTML which seems to do
exactly the same thing?
http://developer.mozilla.org/en/docs/DOM:range.createContextualFragment
Cheers.
Sometimes IE wins, as with innerHTML vs createContextualFragment
Sometimes IE loses, as with document.all s document.getElementById
Sometimes two competing ideas don't win out, as in addEventListener
and attachEvent
--
Paul Wilkins
var s = "<script>alert(1)</script>";
var range = document.createRange();
range.selectNode(document.body);
var documentFragment = range.createContextualFragment(s);
document.body.appendChild(documentFragment);
It looks like you can.
> --
> Paul Wilkins
> I was just wondering why createContextualFragment is available in
> Mozilla browsers when they also have innerHTML which seems to do
> exactly the same thing?
>
> http://developer.mozilla.org/en/docs/DOM:range.createContextualFragment
createContextualFragment in Mozilla was first, then innerHTML support
was implemented with the help of createContextualFragment.
createContextualFragment by now works for XML documents too where you do
not have innerHTML e.g.
var xmlDoc = new DOMParser().parseFromString(
'<root><foo/></root>', 'application/xml');
var node = xmlDoc.documentElement.getElementsByTagName('foo')[0];
var range = xmlDoc.createRange();
range.selectNode(node);
var fragment = range.createContextualFragment(
'<bar>foobar</bar><!-- comment -->');
node.appendChild(fragment);
alert(new XMLSerializer().serializeToString(xmlDoc));
--
Martin Honnen
http://JavaScript.FAQTs.com/