Send to a Friend

derektherock42's avatar

How do I make a picture in an HTML script a clickable link?

Asked by derektherock42 (201points) December 27th, 2009

I’ve been busy building a website for the last couple weeks, and one of the things I did was make the site’s logo (in the upper-left corner) a random picture, so it would randomly show different versions of that logo. I did that using javascript looking something like this:

var altLogos = new Array()

altLogos[0] = ‘altSiteLogo1.gif’
altLogos[1] = ‘altSiteLogo2.gif’
altLogos[2] = ‘altSiteLogo3.gif’
altLogos[3] = ‘altSiteLogo4.gif’

var j = 0
var p = altLogos.length;
var preBuffer = new Array()
for (i = 0; i < p; i++)
{
preBuffer[i] = new Image()
preBuffer[i].src = altLogos[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage()
{
document.write(’<img src=”’+altLogos[whichImage]+’”>’);
}

And then in the <body>,

showImage();

However, I want to make the logo a clickable link, where when you click it, it takes you to the home page. Does anybody with HTML and Javascript knowledge know how to do this? Thanks!

Using Fluther

or

Using Email

Separate multiple emails with commas.
We’ll only use these emails for this message.