Try:
var html = popup.document.documentElement.outerHTML
EDIT
The window is not loaded immediately. Something like this will work, assuming that you're not attempting to violate the same-origin policy:
$('#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 both the parent and the child source, you could also have the child invoke a method on the parent that passes in it's html:
Child Window
// Call when body is loaded
function SendHtmlToParent() {
window.opener.HtmlReceiver(document.outerHTML);
}
Parent
function HtmlReceiver(html) {
console.log(html);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…