To copy a new page you could do something like this:
var yourDOCTYPE = "<!DOCTYPE html..."; // your doctype declaration
var printPreview = window.open('about:blank', 'print_preview');
var printDocument = printPreview.document;
printDocument.open();
printDocument.write(yourDOCTYPE+
"<html>"+
document.documentElement.innerHTML+
"</html>");
printDocument.close();
Source: Copy Current Webpage Into a New Window
How would I write this
printDocument.write(yourDOCTYPE+
"<html>"+
document.documentElement.innerHTML+
"</html>");
so it's just includes #report
? I want the css to be intact, so it's not possible to do this:
printDocument.write(yourDOCTYPE+
"<html>"+
document.getElementById('report').innerHTML+
"</html>");
because then the styling of the origin page is gone.
UPDATE
One option would be to hide all hide all elements in dom except #report
when opened up the new popup-window.
But how do I that in pure js?
If I do something like this in jquery:
$('body > :not(#report)').hide(); //hide all nodes directly under the body
$('#report').appendTo('body');
it would hide eveything except #report
in the original window (of course). I do not understand how to apply this to printDocument.write
(so it applies to the popup window)
I does not have to be a popup window either. It could as well be a new window that opens in browser if someone can give me an idea how to solve this.