document.importNode with a document fragment as its argument.The W3C spec has this to say for document fragments: “If the deep option was set to true, the descendants of the source element are recursively imported and the resulting nodes reassembled to form the corresponding subtree. Otherwise, this simply generates an empty DocumentFragment.”
Safari instead throws a
NOT_SUPPORTED_ERR DOMException (9).Workaround
You can check the
nodeType of your node before calling importNode. If it’s DOCUMENT_FRAGMENT_NODE (11), just call createDocumentFragment on your target document, and then run importNode in a loop over the children of the original document fragment.Compatibilty
Firefox does support this use of
importNode. IE 6 does not support importNode at all. For a cross-browser implementation of importNode, see Anthony Holdener’s article in A List Apart: Cross-Browser Scripting with importNode().
0 comments:
Post a Comment