I am trying to open a new window and pass in some generated html for a report that I am making.
I have stripped down my source code but the following is a working example of my problem.
var windowUrl = "/";
var uniqueName = new Date();
var windowName = "Print" + uniqueName.getTime();
var printWindow = window.open(
windowUrl,
windowName,
"left=0,top=0,width=500,height=500"
);
var link = printWindow.document.createElement('link');
link.rel = 'stylesheet';
link.href = '//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css';
printWindow.document.head.appendChild(link);
printWindow.document.write('<div><section id="divToPrint"><div class="container page-sub">');
printWindow.document.write('<p>Hello World</p>');
printWindow.document.write('</div></section></div>');
printWindow.document.close();
printWindow.focus();
The write method works great, I am able to write my code I need to the DOM but it only writes to the body. Now I need to add information into the head such as styles, title etc... but I am unable to get my head code into the head tag.
Is it even possible to write the head of the new window? when it outputs the head tag looks like this even after adding the link.
<head></head>
I don't know if it is relevant but I am using ReactJS. Maybe there is some sort of alternative.