...

View Full Version : change image and text in iframe



treetop
01-14-2004, 08:16 PM
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

treetop
01-14-2004, 11:13 PM
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>');
}

Garadon
01-14-2004, 11:37 PM
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>

treetop
01-15-2004, 03:38 PM
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?

Garadon
01-15-2004, 04:59 PM
not me I am afraid I only make code to IE.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum