Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2008
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post

    Unhappy Need help with document.write!

    Here is my code:
    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:
    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
    Last edited by zackwiny; 08-07-2008 at 03:24 AM.

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    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);
    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

  • #3
    New Coder
    Join Date
    Aug 2008
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post
    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

    Code:
    <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:
    Code:
    <table id="table1">
    <td>
    Testing 123
    </td>
    </table>
    Last edited by zackwiny; 08-07-2008 at 04:34 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •