1

I would like to open a new window using a url, grab its html as a string and display it in the console of the original window.

From How to get element and html from window.open js function with jquery , I tried:

console.log('response', url)
    var popup = window.open(url, '_blank', 'width=500,height=500');

popup.onload = function() {
    setTimeout(function(){ console.log( 'hi',popup.document.documentElement.outerHTML) }, 2000);
}

The popup window is created, but I don't see the popup's html in the original window's console.

What am I doing wrong?

Community
  • 1
  • 1
user1592380
  • 34,265
  • 92
  • 284
  • 515

1 Answers1

1

If it's not on the same domain, I'm pretty sure it isn't possible as it's not possible with an iframe: Get HTML inside iframe using jQuery.

However, if you own both pages, you should be able to use what is described in the first answer to the SO question you linked to (How to get element and html from window.open js function with jquery)

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);
}
Community
  • 1
  • 1
Jerska
  • 11,722
  • 4
  • 35
  • 54
  • If you try the fiddle on the question you linked to, and change the URL to stackoverflow.com , you'll see that it doesn't work. http://jsfiddle.net/JRqTy/394/ – Jerska Jul 02 '15 at 19:25