views:

29

answers:

1

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

+1  A: 

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();
Jennifer Grucza
Yes, that's exactly what I have except that my HTML includes a stylesheet link:<link rel="stylesheet" type="text/css" href="myStlyes.css" /> The page appears in the new window but without any of the style being applied. Thanks for your response.
Paul
Does it work if you take the HTML you're spitting out to the new window and just put it in a plain HTML file to test? Maybe you just have a typo or wrong path.
Jennifer Grucza