Document.adoptNode () method - HTML - JS

1

I need to develop a page that shows how the method adopNode () works, from what I read it basically removes a node from an external page and loads it into the current document. This is my code, but the H1 tag element is not loaded into the current page:

<html>
<body>
<!-- Carrega página com um elemento de tag H1  -->
<iframe src="ex2.html" style="height:380px;width:520px;"></iframe> 

<button onclick="myFunction()">Try it</button>

   

<script>
function myFunction() {
    var frame = document.getElementsByTagName("IFRAME")[0];
    var h = frame.contentWindow.document.getElementsByTagName("H1")[0];
    var x = document.adoptNode(h);
    document.body.appendChild(x);
}
</script>

</body>
</html>
    
asked by anonymous 31.10.2017 / 16:11

0 answers