[英]how to pass div value to window.open?
我正在尝试将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>
有人可以帮我吗?
我想你想要这个:
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();
( 在jsfiddle.net上演示 )
将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>
它对我有用
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.