我正在尝试将DIV
传递给新窗口。
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>
有人能帮助我吗?
答案 0 :(得分:13)
我想你想要这个:
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();
答案 1 :(得分:0)
将div的id传递给函数。
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>
答案 2 :(得分:0)
对我有用
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();