How to get or call Javascript var in HTML object tag or HTML embed tag from parent html page?

119 Views Asked by At

I have embedded a codmirror html file by 3 different way such as iframe tag, embed tag and object tag inside another html file on the same server.

<!-- The Codemirror Modal window-->
<div id="codeMirrorModal" class="modal">
  <!-- Modal content -->
  <div class="modal-content">
    <span class="close">&times;</span>
    <iframe id="cmIframeId" class="iframeStyle" name="cmiframe" src="../html/codemirror.html" ></iframe>
    
    <embed id="cmEmbed" type="text/html" src="../html/codemirror.html" width="800" height="500">
    
    <object id="cmObject" data="../html/codemirror.html" width="800" height="800" type="text/html"> </object>
    
  </div>
</div>

I can initialize the content of codemirror by iframe but I don't know how to initialize it by embed and object tag.

function openAndInitializeCodeMirror() {
        var modal = document.getElementById("codeMirrorModal");
        modal.style.display = "block";
        
        var content = editor.getContent();

        // with success
        var iframe = document.getElementById("cmIframeId");         
        iframe.contentWindow.codeMirrorEditor.setValue(content);
        
        // no success           
        var embed = document.getElementById("cmEmbed");
        embed.contentDocument.codeMirrorEditor.setValue(content);

        // no success           
        var object = document.getElementById("cmObject");
        var myData = object.contentDocument.body.childNodes[0].innerHTML;

}
    

var codeMirrorEditor is an instance of codemirror on the embedded page.

How can I access or call the codeMirrorEditor instance on the embeded page from parent page to initialize it by my content?

0

There are 0 best solutions below