Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open window in JavaScript with HTML inserted

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

like image 370
williamtroup Avatar asked Jan 21 '10 12:01

williamtroup


People also ask

How do you open a new window with JavaScript?

You can use JavaScript to launch a new window. The window. open() method, which allows you to open up new browser window without navigating away from the current page. It is useful when you need to display some popup advertisement or the instructions without navigating away from the current window.

How do I open a website using JavaScript?

If you want to open URL with JavaScript, the open() method of Window interface is the best option. The JavaScript window. open() method opens a new browser window. Use _blank in the second parameter of window.

How do I make a link open in a new window?

Open in a new window To open a link in a new browser window, hold the Shift on then click the link or right-click the link and select Open link in New Window.


1 Answers

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"; 
like image 150
artnikpro Avatar answered Sep 20 '22 16:09

artnikpro