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 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    change image and text in iframe

    Currently I have a list of links that bring up different pages in an
    iframe on the same page. These pages contain one picture and text explaining the picture. I would like to be able to create these pages from a javascript, to save time creating tons of these little pages.

    I have searched the internet for how to do this with either frames or
    iframes, but the examples leave out code that 'any javascript
    programmer should know what is missing.' I tend to learn by having a
    working code, then figuring out what each part does.

    If anyone has a working example of this, it would be appreciated.

    Thanks
    Treetop

  • #2
    New Coder
    Join Date
    Jan 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have part of it completed, if having some code helps. The following code sets up the list. I want to be able to click on the link with the link title, and display the image and the image title on the same screen. I am willing to use iframe, frames, or whatever works the best.


    var links=new Array();

    links[2]=new Array("picture2.jpg","Pic 2 link title","Pic 2 image title");
    links[1]=new Array("picture1.jpg","Pic 1 link title","Pic 1 image title");

    // and so on ...

    for (var i=links.length-1;i>=0;i--)
    {
    document.write('<a href="' + links[i][0] + '">' + links[i][1] + '</a><br>');
    }

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    note the following is untested but should give u a general idea

    main page:

    var links=new Array();

    links[2]=new Array("picture2.jpg","Pic 2 link title","Pic 2 image title");
    links[1]=new Array("picture1.jpg","Pic 1 link title","Pic 1 image title");

    function showImg(aNum)
    {
    document.IFRAMENAME.setup(links[aNum]);
    }

    // and so on ...

    for (var i=links.length-1;i>=0;i--)
    {
    document.write('<a href="#" onclick=showImg("'+i+'")>' + links[i][1] + '</a><br>');
    }



    the iframe file:


    <script>
    function setup(aLink)
    {
    document.getElementById("pic").src=aLink[0];
    document.getElementById("title").innerHTML=aLink[2];

    }
    </script>
    <body>
    <p id="title"></p>
    <img src="" id="pic">
    </body>

  • #4
    New Coder
    Join Date
    Jan 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you Garadon, this works great with IE.

    I don't suppose you or anybody have the secret to make this work with Netscape 7+ do you?

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    not me I am afraid I only make code to IE.


  •  

    Posting Permissions

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