howto replace document object of a window/iframe

后端 未结 1 455
半阙折子戏
半阙折子戏 2021-01-13 07:20

I need to inject in an iframe window a document object that I instanciated previously, and I cannot serialize it into a string or a remote url (those are solutions proposed

相关标签:
1条回答
  • 2021-01-13 07:48

    Try using importNode:

    /* Change these: */
    var documentToCopy = document,
        iframeDocument = iframe.contentWindow.document;
    
    /* Replace current document-element (<html>) with the new one: */
    iframeDocument.replaceChild(
        iframeDocument.importNode(documentToCopy.documentElement, true),
        iframeDocument.documentElement
    );
    

    See https://developer.mozilla.org/en/DOM/document.importNode

    0 讨论(0)
提交回复
热议问题