Edit HTML of a different document .html

0

Good morning,

I am trying to make an innerHTML to an HTML that is not from which the function has been called. I hope that the code is better understood.

function ventana_cargada() {

       var ventanaPadre = window.opener;
       console.log(ventanaPadre);

       document.getElementById("carga_completada").innerHTML = "<b>Ventana cargada correctamente.</b>";  
}

The purpose of this is that I have opened a new window with "window.open", and I need to edit the HTML of the file that this case has opened this window. As you can see in the code I have managed to get the URL of the html that I want to edit with "window.opener" but now I do not know how to make the innerHTML function do it to the parent html file.

Thanks in advance!

    
asked by Pau G.P. 13.05.2017 в 20:57
source

1 answer

0

You have not defined the open window var newWindow = window.open("", "newWindow", "width=200,height=100"); to know what is the opener of this window var ventanaPadre = newWindow.opener;

<p id='carga_completada'></p>


<button onclick="ventana_cargada()">abrir nueva ventana</button>

<script>
function ventana_cargada() {
    var newWindow = window.open("", "newWindow", "width=200,height=100");
    var ventanaPadre = newWindow.opener;
    newWindow.document.write("<p>Esta es la nueva ventana</p>");
    ventanaPadre.document.getElementById("carga_completada").innerHTML = "<b>ventana padre de la nueva ventana</b>"; 

}
</script>

Example in try it

    
answered by 13.05.2017 в 21:29