Forum Moderators: open
I tried:
<a href="javascript:document.getElementById('main_content').innerHTML;">Open</a>
Following this way it's possible to obtain the content in the div, but i can't figure out how to open a new window filled with it.
What's the solution?
TIA,
Paolo
When you open your window, give it a name, as in:
myWin=window.open("","myWin","menubar,scrollbars,left=30px,top=40px,height=400px,width=600px");
Then write the variable to the window, as in (using myVar as the variable name):
myWin.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">'+
'<html><head><title>My Window</title></head><body>' + myVar + '</body></html>')
But I'm stumped again :(
Now I need that the content will be displayed into a div (with id='dest_div') of the new window (called main_content).
I tried to execute the following code.. without success:
var newWin=window.open('main_content','newWin','menubar,scrollbars,left=30px,top=40px,height=400px,width=600px');
var orig_div=document.createTextNode(document.getElementById("content").innerHTML);
var dest_div=newWin.document.getElementById("dest_div");
dest_div.appendChild(orig_div);
Would you help? Basic tutorials about dom are also welcome!
Thanks again,
Paolo
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Writing text to window 04.06.04</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript">
<!--
function doWin(){
var orig_div_cont=document.getElementById("content").innerHTML;
var myWin=window.open("","myWin","menubar,scrollbars,left=30px,top=40px,height=400px,width=600px");
myWin.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">'+
'<html><head><title>My Window</title></head><body><div id="dest_div">'+
'Some original division content. <br /></div></body></html>');
myWin.document.close();
myWin.document.getElementById("dest_div").innerHTML+=orig_div_cont;
}
//-->
</script>
</head>
<body onload="doWin();">
<div id="content">Content from the first page's division. </div>
</body>
</html>
My favorite resources for programming DHTML are the O'Reilly books, "JavaScript: The Definitive Guide" by David Flanagan, ISBN 0-596-00048-0 and "Dynamic HTML" by Danny Goodman, ISBN 0-596-00316-1.