howto replace document object of a window/iframe

后端 未结 1 483
半阙折子戏
半阙折子戏 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 () with the new one: */
    iframeDocument.replaceChild(
        iframeDocument.importNode(documentToCopy.documentElement, true),
        iframeDocument.documentElement
    );
    

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

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