Reputation: 209
I'm trying to pass a DIV
to a new window.
function openWin() {
myWindow=window.open('','','width=200,height=100');
}
<div id="pass">pass this to the new window</div>
<a href="#" onclick="openWin();">click</a>
Can someone help me out?
Upvotes: 3
Views: 36448
Reputation: 11
it worked for me
var divText = document.getElementById("id").outerHTML;
var myWindow = window.open('','','width=200,height=100');
var doc = myWindow.document;
doc.open();
doc.write(divText);
doc.close();
Upvotes: 1
Reputation: 664185
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();
Upvotes: 16
Reputation: 160833
Pass the id of the div to the 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>
Upvotes: 0