How to pass div value to window.open?

I am trying to pass a DIV to a new window.

Javascript

 function openWin() { myWindow=window.open('','','width=200,height=100'); } 

HTML

 <div id="pass">pass this to the new window</div> <a href="#" onclick="openWin();">click</a> 

Can someone help me?

+2
source share
2 answers

I think you want this:

 var divText = document.getElementById("pass").outerHTML; var myWindow = window.open('','','width=200,height=100'); var doc = myWindow.document; doc.open(); doc.write(divText); doc.close(); 

( Demo on jsfiddle.net )

+13
source

Pass id div to function.

  function openWin(id) { var divText = document.getElementById(id).innerHTML; myWindow=window.open('','','width=200,height=100'); } <div id="pass">pass this to the new window</div> <a href="#" onclick="openWin('pass')" />click</a> 
+1
source

All Articles