On the MDN page for importNode, it says:
Before they can be inserted into the current document, nodes from external documents should either be:
cloned using document.importNode(); or
adopted using document.adoptNode().
It’s been a while since I’ve done anything involving multiple documents, and maybe I’m a little rusty, but I always thought the should in the snippet above was an indicator that you’d get an exception if you tried to add a foreign element without calling either function first.
I tried this in Edge’s console and there didn’t seem to be a problem moving nodes between documents.
let a = new Document();
let b = new Document();
b.appendChild(b.createElement("div"));
b.childNodes;
> NodeList [div]
b.firstChild.ownerDocument === b
> true
a.appendChild(b.firstChild);
a.childNodes;
> NodeList [div]
a.firstChild.ownerDocument === a
> true
b.childNodes;
> NodeList []
I seem to recall browsers being more hostile to this kind of manoeuvring in the past. Under what circumstances should I expect this to not work and give me an exception? Is it because there are no namespace differences? Are nodes auto-adopted? Have I made the Document objects the wrong way?