locked
HOWTO pass a cloned node with all scripts, styles, and events to a popup window. RRS feed

  • Question

  • HOWTO pass a cloned node with all scripts, styles, and events to a popup window.

    Please help,

    I want to use createPopup to make a popup window, and then pass a cloned noed to the popup as its body, and still have all the of original node's script functional from within the popup.

    So far I figured out how to copy the styles and scripts, and they work great as such:

      var objPOPUP = window.createPopup();

      for (i = 0; i < document.styleSheets.length; i++)
      {
        objPOPUP.document.createStyleSheet(document.styleSheets[i].href);
      }

      var csPOPUP_BODY = "";

      for (i = 0; i < document.scripts.length; i++)
      {
        csPOPUP_BODY += document.scripts[i].outerHTML;
      }

      objPOPUP.document.body.innerHTML = csPOPUP_BODY;

    Now I need to figure out how to clone a given node, with all of its events, to put into the popup. So far, I have tried things liek this:

      var objClone = objMyTargetIWantCloned.cloneNode(true);

      objPOPUP.document.body.appendChild(objClone);

    This does not seem to work. And it does not bring any attached events the original node may have had.

    Ultimately, I had to get the outerHTML of the target node, and concatenate it to the popup's body, kind of like this:

      csPOPUP_BODY += objMyTargetIWantCloned.outerHTML;
      objPOPUP.document.body.innerHTML = csPOPUP_BODY;

    But again, this does not bring attached events on the target node into the popup.

    Any ideas?

    Thursday, March 18, 2010 6:36 PM