deidara song
deidara song

Reputation: 209

how to pass div value to window.open?

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?

Upvotes: 3

Views: 36448

Answers (3)

jitendra
jitendra

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

Bergi
Bergi

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

(Demo at jsfiddle.net)

Upvotes: 16

xdazz
xdazz

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

Related Questions