How can I get a string from an iframe to a div on the parent page?

16 Views Asked by At

I want to delay the execution of a parent.window function called in an iframe until AFTER an iframe-generated string is passed to the parent.

Right now, the string is not passed until the parent.window function is completed.

I prefer in to use the postMessage() method because of security issues.

As you can tell, I am a newbie.

<script type="text/javascript">
  function reply_click(clicked_id) {
    var thisLine = clicked_id;
    var txtFile = new XMLHttpRequest();  
    txtFile.open("GET", "_Anonymous.txt", true);  
    txtFile.onreadystatechange = function() {  
        if (txtFile.readyState === 4) {  
            // Makes sure the document is ready to parse.  
        if (txtFile.status === 200) {  
            // Makes sure it's found the file.  
            var fullText = txtFile.responseText;                               
            const myArray = fullText.split("\n");
            let cQuote = myArray.at(thisLine);
            parent.document.getElementById("originalQuote").innerHTML = cQuote;
            parent.setup();         
                    }  
                }  
            }  
            txtFile.send(null)              
}
</script>
0

There are 0 best solutions below