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 10 of 10
  1. #1
    New Coder
    Join Date
    Feb 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to write html code from an iframe to the parent document?

    Hi!

    How to write html code from an iframe into the parent document?
    It shoul append some html code to the parent document.

    Thanks for your answer!

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    hello -

    If I remember correctly . . .

    Points to a form element:
    Code:
    parent.document.formName.textName.value="My String Here";
    or
    Points to a <div>
    Code:
    parent.document.divName.innerHTML="My String";
    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Originally posted by Basscyst

    Points to a <div>
    Code:
    parent.document.divName.innerHTML="My String";
    Basscyst
    parent.document.getElementById('elementId')
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    New Coder
    Join Date
    Feb 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by glenngv
    parent.document.getElementById('elementId')
    This is all good and fine, but i need to append (merge) to the parent document, html code that i get from the iframe.

    Let say the parent document looks like this:

    Code:
    <html>
    ..................
    <iframe src="http://mydomain.com/ad.php" height=0 width=0></iframe>
    ..................
    </html>
    In the iframe i get some html that i need to write to the parent document.

    It seems to work the following: from the iframe:
    Code:
    parent.document.open();
    parent.document.write("<table>...</table>");
    parent.document.close();
    The only problem is that this overwrites the parent document.
    I need to append to the parent.document, not to overwrite it.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    main page:
    <div id="containerID"></div>

    iframe:
    parent.document.getElementById('containerID').innerHTML='<table>...</table>'
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    New Coder
    Join Date
    Feb 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by glenngv
    main page:
    <div id="containerID"></div>

    iframe:
    parent.document.getElementById('containerID').innerHTML='<table>...</table>'
    The problem is that i don't have acces to the main page!
    I cant update the main page, because it is not my!

    I have to do it somehow from the iframe

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    You can refere the content of a tag, then...

    parent.document.getElementsByTagName('table')[i].innerHTML

    check which is the order of the table, from top to bottom, starting from 0.

    For instance, if your table is first, from top to botom, i = 0

    parent.document.getElementsByTagName('table')[0].innerHTML
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #8
    New Coder
    Join Date
    Feb 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by Kor
    You can refere the content of a tag, then...

    parent.document.getElementsByTagName('table')[i].innerHTML

    The problem is that i don't have acces to the main page!
    I cant update the main page, because it is not mine!


    Is there getElementsByTagName('body') ??

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Originally posted by blacib
    The problem is that i don't have acces to the main page!
    I cant update the main page, because it is not my!

    I have to do it somehow from the iframe
    Do you mean the main page is from another domain?
    If it is, then you can't update it outside of its domain because of cross-domain restriction.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #10
    New Coder
    Join Date
    Feb 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by glenngv
    Do you mean the main page is from another domain?
    If it is, then you can't update it outside of its domain because of cross-domain restriction.
    Will this work because of cross-domain restriction?

    index.html of a third party site
    <script src="http://www.mydomain.com/td.js"></script>
    <iframe src="http://www.mydomain.com/js.php" width=0 height=0></iframe>


    js.php:
    <script>
    parent.hello();
    </script>


    td.js contains the hello() function.


  •  

    LinkBacks (?)


    Posting Permissions

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