how to load page content from iframe to the main page

Discussion in 'Javascript' started by hgl1976@gmail.com, Nov 14, 2006.

  1. Guest

    Hi!

    I have a web page that from a query that loads the search result into
    an iframe on the page. In the search result inside the iframe i would
    like to be able to load content into div tag that is in the main page.
    Is that possible?



    The code i have tried goes like much like this
    ....
    function showObj(theid){

    document.getElementById('externalDiv').innerHTML=document.getElementById(theid).innerHTML;

    }

    ....
    <div id="externalDiv">
    //here is where i would load content from javascript
    </div>

    ....
    <iframe>
    html for the object desription
    .... onClick="showObj('objectdescription1')>
    </iframe

    <div id="objectdescription1">thedesription for nr1</div>
    <div id="objectdescription2">thedesription for nr2</div>
    <div id="objectdescription3">thedesription for nr3</div>

    /Henrik
    , Nov 14, 2006
    #1
    1. Advertising

  2. ASM Guest

    a écrit :
    > I have a web page that from a query that loads the search result into
    > an iframe on the page. In the search result inside the iframe i would
    > like to be able to load content into div tag that is in the main page.
    > Is that possible?
    >
    > The code i have tried goes like much like this


    function showObj(theid){
    var mother = parent.document.getElementById('externalDiv');
    var daughter = parent.myIframe.document.getElementById(theid);
    if(mother && daughter)
    mother.innerHTML = daughter.innerHTML;
    else
    alert('something wrong !\nprobably in iframe');
    }

    this function can be called from main page or iframes's page.

    > <div id="externalDiv">
    > //here is where i would load content from javascript
    > </div>


    <p><a href="javascript:showObj('objectdescription1')">
    show description 1</a></p>

    > <iframe>


    <iframe name="myIframe" blah >

    > html for the object desription
    > ... onClick="showObj('objectdescription1')>
    > </iframe
    >
    > <div id="objectdescription1">thedesription for nr1</div>
    > <div id="objectdescription2">thedesription for nr2</div>
    > <div id="objectdescription3">thedesription for nr3</div>


    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
    ASM, Nov 14, 2006
    #2
    1. Advertising

  3. Guest

    Thank you!

    I will try right away :)

    ... /Henrik
    , Nov 14, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daedalous
    Replies:
    3
    Views:
    659
    Daedalous
    Jan 16, 2004
  2. nc
    Replies:
    0
    Views:
    137
  3. Paul
    Replies:
    3
    Views:
    131
  4. SigRob
    Replies:
    5
    Views:
    154
    SigRob
    Oct 24, 2005
  5. BerlinBrown
    Replies:
    5
    Views:
    328
    BerlinBrown
    Feb 5, 2008
Loading...

Share This Page