I have some JavaScript in a page that makes a call to a server and gets some HTML that I want to display in a new browser tab or window. I can use window.document.write(myHTML) to put the HTML in the new container but the HTML contains some CSS and JavaScript includes and these do not get included by the new window. Is there any way to get the browser to take the HTML and fully evaluate it?
Thanks
Paul
Can you post your example javascript and the HTML you're writing to the window (or a stripped down test case, really)? If you're writing out a full HTML document (including html/head/body elements) using newWindow.document.write, it should work. Does your javascript look something like this?
var newWindow = window.open();
newWindow.document.write("<html><head><script type='text/javascript' src='yourCode.js'></scr"+"ipt></head><body>Your content</body></html>");
newWindow.document.close();
this worked for me.. the code doesn't seem to work in the editor here but you can try it in your browser console..
var newTab = window;
var pageContent = "<head> your html head should be here </head>";
pageContent += "<body> the body should be <a class='heads'>here</a> </body>";
newTab.open().document.write(pageContent);
.heads{
font-size:50px;
color: green;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With