Sometimes, we want to open window in JavaScript with HTML inserted.
In this article, we’ll look at how to open window in JavaScript with HTML inserted.
How to open window in JavaScript with HTML inserted?
To open window in JavaScript with HTML inserted, we can set the innerHTML property of the window’s body element.
For instance, we write
const win = window.open(
"",
"Title",
"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=200,top=" +
(screen.height - 400) +
",left=" +
(screen.width - 840)
);
win.document.body.innerHTML = "HTML";
to call window.open with a string with the dimensions and other settings of the window.
Then we set win.document.body.innerHTML to the HTML string we want to render in the window.
Conclusion
To open window in JavaScript with HTML inserted, we can set the innerHTML property of the window’s body element.