Web Analytics Made Easy -
StatCounter How to write html code from an iframe to the parent document? - CodingForum

Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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

    Comment


    • #3
      Originally posted by Basscyst

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

      Comment


      • #4
        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.

        Comment


        • #5
          main page:
          <div id="containerID"></div>

          iframe:
          parent.document.getElementById('containerID').innerHTML='<table>...</table>'
          Glenn
          vBulletin Mods That Rock!

          Comment


          • #6
            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

            Comment


            • #7
              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
              -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

              Comment


              • #8
                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') ??

                Comment


                • #9
                  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
                  vBulletin Mods That Rock!

                  Comment


                  • #10
                    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.

                    Comment

                    Working...
                    X