11

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
  • 4,943
  • 11
  • 45
  • 72

3 Answers3

20
var opened = window.open("");
opened.document.write("<html><head><title>MyTitle</title></head><body>test</body></html>");
M. A. Kishawy
  • 4,943
  • 11
  • 45
  • 72
Fabien Ménager
  • 139,991
  • 3
  • 39
  • 60
3
var w = window.open("");
w.document.writeln("<the html you wanted to write>")
Roy Tang
  • 5,413
  • 9
  • 42
  • 72
2
function fu() {
  var opened = window.open("");
  opened.document.write("Your HTML here");
}
Emil Vikström
  • 87,715
  • 15
  • 134
  • 170