Translate HTML from the current page to a new window

I want to open a new window and transfer some of the HTML on the original page to a new window. What is the easiest way to do this?

Sort of:

$("div#foo").click( function(){ var copyHTML = $("table.bar").html(); window.open(''); // somehow put copyHTML in the new window }); 
+4
source share
1 answer

Try the following:

 $("div#foo").click ( function() { var copyHTML = $("table.bar").html(); var newWindow = window.open(''); newWindow.document.body.innerHTML = copyHTML; } ); 

This will work in some cases, and it will be easier than the following approach.

If you get security warnings in your browser, the following approach may be more enjoyable. Add a function to the parent page named getContent, for example:

 function getContent() { return $("table.bar").html(); } 

... and on document.ready in the child window do the following:

 $(document).ready ( function() { var parentContent = window.opener.getContent(); $("body").html(parentContent); } ); 
+2
source

All Articles