Globally declare the variable var Frame=null; , then on an event I create and fill it with the contents:

 Frame = document.createElement("iframe"); Frame.id = "iframe"; Frame.style.width = "30%"; Frame.style.height = "30%"; Frame.src = targetlink; document.body.appendChild(Frame); 

In it, the user can perform some actions and, accordingly, its contents change.
At some point, the user clicks a button on the main page and the frame content should appear on the page itself, and the frame will close.

Attempt to do like this: document.body = Frame.document.body; does not work. How to transfer the contents of the frame?

    1 answer 1

     <button onclick='drag()'>перенести</button> 
     var Frame = null; Frame = document.createElement('iframe'); Frame.id = 'iframe'; Frame.style.width = '30%'; Frame.style.height = '30%'; Frame.src = targetlink; document.body.appendChild(Frame); function drag() { Frame.outerHTML = Frame.contentWindow.document.body.innerHTML; } 

    Or you can use the content retrieval site

     function drag() { getHTML('http://ru.stackoverflow.com', function(html) { Frame.outerHTML = html; }); } function getHTML(url, c) { request(new XMLHttpRequest()); function request(xhr) { xhr.open('GET', 'https://crossorigin.me/' + url, true); xhr.send(); xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) { c(xhr.responseText); } } } } 
    • Not all sites allow you to use iframe or transfer to yourself. iframe checker to help. Checked on localhost. It should be understood that transferring content from an iframe can affect the lack of images or other downloadable items due to links inside the frame - Mr. Black