views:

74

answers:

3

I would like to make a button on a page that can call a JS function in the same page. the function will need to produce (open) new window which its HTML code was given from the JS function itself. How can I do that?

The purpose of this is to produce a print friendly page out of a specific page. Please notice: No AJAX can be used.

+2  A: 
var w = window.open("");
w.document.writeln("<the html you wanted to write>")
Roy Tang
it opens new window however it doesn't write anything in it!!!
MAK
+2  A: 
function fu() {
  var opened = window.open("");
  opened.document.write("Your HTML here");
}
Emil Vikström
it opens new window however it doesn't write anything in it!!
MAK
It works for me in Firefox. Which browser are you trying this in, and do you get any errors?
Emil Vikström
No errors! but it looks like it won't show the text you write unless you use the HTML properties as Fabien wrote. Thanks
MAK
+1  A: 
var opened = window.open("");
opened.document.write("<html><head><title>My title</title></head><body>test</body></html>");
Fabien Ménager