How can I make javascript to create a new page?

I would like to make a button on the page that can call the JS function on the same page. The function will have to create (open) a new window, which its HTML code was given from the JS function itself. How can i do this?

The purpose of this is to create a page that supports printing on a specific page.

Please note: AJAX cannot be used.

+6
javascript html printing website
source share
3 answers
var opened = window.open(""); opened.document.write("<html><head><title>MyTitle</title></head><body>test</body></html>"); 
+12
source share
 var w = window.open(""); w.document.writeln("<the html you wanted to write>") 
+3
source share
 function fu() { var opened = window.open(""); opened.document.write("Your HTML here"); } 
+2
source share

All Articles