javascript - how to pass domnode to the sub window created by window.open -


When we add children to B.js, then there is an undefined error I ??

  / / sample code //A.js this.node = document.getElementById ("area"); window.open ("B.html"); //B.js Document.getElementById ("Area"). AppendChild (window.opener.node);    

document in BJS is one of the #document in AJ . It means window.opener.node is a #document with an node and therefore you have to call before using it < / P>

  // B.js var node = document.importNode (window.opener.node, / * deep * / true); document.getElementById ("area") appendChild (node).   

Please note that this new node is a copy , if you have large structures then you also want to delete the original You can. / P>


If you want to support older IE browsers that have reached the end of your life, here are some things


a & lt ; Div & gt; Setting and internal HTML

  if (! Document.importNode) {document.importNode = function (node, dark) {var wrapper_old = Node.ownerDocument.createElement ('Div'), wrapper_new = document.createElement ('div'); wrapper_old.appendChild (node.cloneNode (deep !!); Wrapper_new.innerHTML = wrapper_old.innerHTML; Return wrapper_new.removeChild (wrapper_new.firstChild); }; }   

call it & lt; Div & gt;


can have a child who should work on everything cloneNode from its new #document (I Have not tested)

  if (! Document.importNode) {document.importNode = function (node, deep) {return node.prototype.cloneNodecoll (node, !! deep); }; }   

Assuming this works, it will work for more nodes , but id attributes will skip

  If (! Document.importNode) {document.importNode = function ( 

Node, deep) {Var E, I, A; If (node.Nodtip === 3) // #text return document. CreateTextNode (nodeadata); If (node.Nodtip === 8) // # Comment Return Document .create comment (node); If (node.Nodtip! == 1) // #Document / Other new type throw error ('unsupported node type:' + node. Node type); // Element E = document. CreateElement (node.tagName); A = node. Features; (I = 0; i & lt; a.length; ++ i) for {e.setAttribute (a [i] .name, a [i] .value); } If (deeper) for (i = 0; i & lt; node.childNodes.length; ++ i) {e.appendChild (clone (node.cildnode [i])); } Return e; }; }

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -