Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make JavaScript make (produce) new page?

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.

like image 304
M. A. Kishawy Avatar asked Jan 05 '10 06:01

M. A. Kishawy


People also ask

How do I open another page in JavaScript?

The JavaScript window. open() method opens a new browser window. Use _blank in the second parameter of window. open() method to open a URL in a new tab using JavaScript.

Can I develop website using JavaScript?

In short, JavaScript is a programming language that lets web developers design interactive sites. Most of the dynamic behavior you'll see on a web page is thanks to JavaScript, which augments a browser's default controls and behaviors.


2 Answers

var opened = window.open("");
opened.document.write("<html><head><title>MyTitle</title></head><body>test</body></html>");
like image 130
Fabien Ménager Avatar answered Sep 30 '22 16:09

Fabien Ménager


var w = window.open("");
w.document.writeln("<the html you wanted to write>")
like image 35
Roy Tang Avatar answered Sep 30 '22 16:09

Roy Tang