问题
I'm 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 out?
回答1:
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 at jsfiddle.net)
回答2:
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>
回答3:
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();
来源:https://stackoverflow.com/questions/12311268/how-to-pass-div-value-to-window-open