Open window in JavaScript with HTML inserted

williamtroup picture williamtroup · Jan 21, 2010 · Viewed 134.5k times · Source

How would I open a new window in JavaScript and insert HTML data instead of just linking to an HTML file?

Answer

artnikpro picture artnikpro · Sep 29, 2013

I would not recomend you to use document.write as others suggest, because if you will open such window twice your HTML will be duplicated 2 times (or more).

Use innerHTML instead

var 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";