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?

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)

Display div element content in a new popup window, I think you want this: var divText = document.getElementById("pass").outerHTML; var myWindow = window.open('','','width=200,height=100'); var doc  On home.html, if I enter a value into #txtinput and click #btn, I want to open result.html and pass the value of #txtinput into #txtresult. I've tried the below code from another post, which displays the value in the new window's body but won't display it in my element

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>

Print the content of a div element using JavaScript, Here we are going to show the element content in a new window on clicking a Before we going to see how to open and show our div element content in the new innerHTML;; var newWindow = window.open("", "", "width=500,height=400"); So we just have to pass the variable inside the document write() method what  To put it short 'value' is not an valid attribute of div. So it's absolutely correct to return undefined. What you could do was something in the line of using one of the HTML5 attributes 'data-*'

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

Print certain div / elements using window.print() · GitHub, innerHTML;. var a = window.open('', '', 'height=500, width=500');. a.document.​write('< html >');. a.document.write('< body > < h1 >Div contents are < br >');. A window which is opened by your main window will architecturally be unable to share the same scope with its parent. Because the angular scope is defined per DOM element.

Window parent Property, innerHTML = printContents;. window.print();. document.body.innerHTML = originalContents;. } </script>. <h1> do not print this </h1>. <div id='printMe'>. Print this  how to pass div value to window.open? Ask Question Asked 7 years, 8 months ago. Active 1 year, 6 months ago. Thanks for contributing an answer to Stack Overflow!

How pass array in window.open() in Javascript, Change the background-color of an <iframe> element's parent document: Return Value: The parent window object of the current window. More Examples. Example. Alert the location of the parent window when opening a new window:. Definition and Usage. The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.

Window.open(), You could try to pass a array to a new window in this way. Main page: <div> <​input id="btnopen" type="button" value="Open A New Window"  If you use a variable with one of the primitive data types to pass your argument, the argument passes by value. What this means is the new variable created inside the function is totally separate from the variable used to pass the argument, and no matter what happens after the value gets into the function, the variable outside of the function

Comments
  • The div has no "value" property. What exactly are you trying to do?
  • You haven't used 'divText' while opening new window. How this is supposed to work?