how to load page content from iframe to the main page

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

  1. hgl1976

    hgl1976 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
     
    hgl1976, Nov 14, 2006
    #1
    1. Advertisements

  2. hgl1976

    ASM Guest

    a écrit :
    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.
    <p><a href="javascript:showObj('objectdescription1')">
     
    ASM, Nov 14, 2006
    #2
    1. Advertisements

  3. hgl1976

    hgl1976 Guest

    Thank you!

    I will try right away :)

    ... /Henrik
     
    hgl1976, Nov 14, 2006
    #3
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.