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.
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.
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.
var opened = window.open("");
opened.document.write("<html><head><title>MyTitle</title></head><body>test</body></html>");
var w = window.open("");
w.document.writeln("<the html you wanted to write>")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With