Results 1 to 6 of 6

Thread: Data inside an iframe and a span

  1. #1
    Join Date
    Nov 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Data inside an iframe and a span

    ok, so i have this html with this code in the body

    Code:
    <div id = "info">blahblahblah</div>
    <span id = "iframespan"><iframe src="page.php" name="iframepage" id="iframe"></iframe></span>
    and inside the page.php
    Code:
    <script>
    ?????
    </script>
    <div id="outer>
     <div id="content">
      blah blah blah
     </div>
    </div>
    so i want it that when it loads, the content of "info" is transferred to the content of "content". Please help.

  2. #2
    Join Date
    Nov 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    bump.

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    In the page.php you can add the following code in your client-side script tags.

    Code:
    window.onload = function(){
     document.getElementById('content').innerHTML = parent.window.document.getElementById('info').innerHTML;
    }
    The above code will trigger as the load event of your iframe window. Hope this help

  4. #4
    Join Date
    Nov 2007
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    uhmm.. thanks! how do you do it reversely? from the parent document?

  5. #5
    Join Date
    Dec 2007
    Location
    Ankara, Turkey
    Posts
    160
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default

    The reverse way may not work on all browsers correctly due to some security restrictions but as you can see above, you simply change the "getter" and "setter" elements like below:
    Code:
    parent.window.document.getElementById('info').innerHTML = document.getElementById('content').innerHTML;

  6. #6
    Join Date
    Jan 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by lordjeremiahs View Post
    uhmm.. thanks! how do you do it reversely? from the parent document?
    I think that :
    var iframeObj = document.getElementById('iframe');
    var temp = '';
    if (iframeObj.contentDocument)
    {
    temp = iframeObj.contentDocument.getElementById('content').innerHTML;
    }
    else if(iframeObj.contentWindow)
    {
    temp = iframeObj.contentWindow.document.getElementById('content').innerHTML;
    }
    else if(iframeObj.document)
    {
    temp = iframeObj.document.getElementById('content').innerHTML;
    }
    document.getElementById('info').innerHTML = temp;

Bookmarks

Posting Permissions

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