Try:
var html = popup.document.documentElement.outerHTML
EDIT
The window does not load immediately. Something like this will work, assuming you are not trying to violate a policy of the same origin :
$('#btn').click(function() { var popup = window.open('[Your URL HERE]', '_blank', 'width=500,height=500'); popup.onload = function() { setTimeout(function(){ console.log(popup.document.documentElement.outerHTML) }, 2000); } });β
Here's a working fiddle .
Note. . If you control the parent and child source, you can also force it to call the method of the parent element that passes html in it:
Children's window
// Call when body is loaded function SendHtmlToParent() { window.opener.HtmlReceiver(document.outerHTML); }
Parent
function HtmlReceiver(html) { console.log(html); }
source share