如何将div值传递给window.open?

时间:2012-09-07 03:20:12

标签: javascript popup

我正在尝试将DIV传递给新窗口。

的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>

有人能帮助我吗?

3 个答案:

答案 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();

Demo at jsfiddle.net

答案 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();