Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to link images?

Status
Not open for further replies.

qban21

Programmer
Aug 12, 2002
11
US
Good morning,

I'm working with a piece of javascript code that I inherited and I'm trying to get the images to link to certain pages. I'm not great with javascript! :) Below is the code that I'm working with. So, I would need welcome1 to go to ex.html, welcome2 to ex2.html, etc. Can you guys point me in the right direction? Thanks!

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var timeDelay = 5; // change delay time in seconds
var Pix = new Array
("images/welcome1.gif"
,"images/welcome2.gif"
,"images/welcome3.gif"
,"images/welcome4.gif"
,"images/welcome5.gif"
,"images/welcome6.gif"
);
var howMany = Pix.length;
timeDelay *= 1000;
var PicCurrentNum = 0;
var PicCurrent = new Image();
PicCurrent.src = Pix[PicCurrentNum];
function startPix() {
setInterval("slideshow()", timeDelay);
}
function slideshow() {
PicCurrentNum++;
if (PicCurrentNum == howMany) {
PicCurrentNum = 0;
}
PicCurrent.src = Pix[PicCurrentNum];
document["ChangingPix"].src = PicCurrent.src;
}
</script>
// End -->

<body onLoad="startPix()">
<img src="images/welcome1.gif" name="ChangingPix" border="0" align="middle">
</body>
 
Wrap an anchor around your image, and set its HREF attribute to point to the place where the initial image should go. Make sure this anchor has an ID, something like 'imageLink'.

Then, have a second array with the same number of items as 'Pix', but containing strings that are equivalent to the URLs you wish each picture to go to.

Then, when setting the src of the image, set the HREF attribute of the link at the same time, something like:

Code:
document.getElementById('imageLink').href = yourHrefArrayNameHere[PicCurrentNum];

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi

Sounds like a bad joke. And your code looks like a bad joke.
JavaScript:
function slideshow()
{
  PicCurrentNum++;
  if (PicCurrentNum == howMany) {
    PicCurrentNum = 0;
  }
  PicCurrent.src = Pix[PicCurrentNum];
  document["ChangingPix"].src = PicCurrent.src;
  [red]document["ChangingPix"].parentNode.href = 'ex'+(PicCurrentNum==1?'':PicCurrentNum)+'.html';[/red]
}
HTML:
[red]<a href="ex.html">[/red]<img src="images/welcome1.gif" name="ChangingPix" border="0" align="middle">[red]</a>[/red]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top