...

View Full Version : Need help with document.write!



zackwiny
08-07-2008, 12:21 AM
Here is my code:

<html>
<head>
<SCRIPT>
function showFrameText()
{
d = document.getElementById("iframeholder");
k = d.contentWindow.document.getElementById("table1").innerHTML;
return k;
}
function init()
{
var innerstuff = '<table>' + showFrameText() + '</table>';
alert(innerstuff);
document.write(innerstuff);
}
</SCRIPT>
</head>
<body>
<iframe onload="init()" src="index2.html" id="iframeholder" name="iframeholder">if you see this you have iframes turned off.</iframe>
</body>
</html>

Here is index2.html's code:

<table id="table1" border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>

The problem is that the innerstuff variable is blank for the document.write command but not for the alert command,
i need help making it work,

Thanks

binaryWeapon
08-07-2008, 03:06 AM
<html>
<head>
<SCRIPT>
function showFrameText()
{
d = document.getElementById("iframeholder");
k = d.contentWindow.document.getElementById("table1").innerHTML;
return k;
}
function init()
{
var innerstuff = '<table>' + showFrameText() + '</table>';
alert(innerstuff);
d = document.getElementById("iframeholder");
d.contentWindow.document.write(innerstuff);
}
</SCRIPT>
</head>
<body>
<iframe onload="init()" src="index2.html" id="iframeholder" name="iframeholder">if you see this you have iframes turned off.</iframe>
</body>
</html> Should work. However, it overwrites the existing page in index2.html, I don't know if this is what you are going for, so if you just want to append then I would use .innerHTML+= instead.

Regards,
~ bW

zackwiny
08-07-2008, 03:23 AM
Well the .innerHTML+= thing didn't work,
it wouldn't do anything after that,
but i guess i can just use the script u gave me but with a second iframe

Edit:
Well here is my new code...
if it's useful to anyone else


<html>
<head>
<SCRIPT>
function showFrameText(getframe,getelement) {
var f1 = document.getElementById(getframe);
var result = f1.contentWindow.document.getElementById(getelement).innerHTML;
return result;
}
function init(frameone,frametwo,elementone) {
var innerstuff = showFrameText(frameone,elementone);
var f2 = document.getElementById(frametwo);
f2.contentWindow.document.write(innerstuff);
}
</SCRIPT>
</head>
<body>
<iframe id="frame2" name="frame2" frameborder=0 width="100&#37;" height="100%" scroll="no"></iframe>
<iframe onload="init('frame1','frame2','table1')" src="index2.html" id="frame1" name="frame1" width=0 height=0 frameborder=0></iframe>
</body>
</html>

index2.html:

<table id="table1">
<td>
Testing 123
</td>
</table>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum