How can I make JavaScript make (produce) new page?
34,802
Solution 1
var opened = window.open("");
opened.document.write("<html><head><title>MyTitle</title></head><body>test</body></html>");
Solution 2
var w = window.open("");
w.document.writeln("<the html you wanted to write>")
Solution 3
function fu() {
var opened = window.open("");
opened.document.write("Your HTML here");
}
Comments
-
M. A. Kishawy about 4 years
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 create (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.
-
M. A. Kishawy over 14 yearsit opens new window however it doesn't write anything in it!!
-
Emil Vikström over 14 yearsIt works for me in Firefox. Which browser are you trying this in, and do you get any errors?
-
M. A. Kishawy over 14 yearsNo errors! but it looks like it won't show the text you write unless you use the HTML properties as Fabien wrote. Thanks