/    Sign up×
Community /Pin to ProfileBookmark

How to attach URL Link to Javascript Image?

Here is the website in question:

http://www.addaxtactical.com

Basically the client now wants me to make the random image script images a link back to the home page. Simple, right? Well I can’t quite figure it out since they are javascript. How do I do this?

<script language=”JavaScript”>
var theImages = new Array()

theImages[0] = ‘adxwide.png’
theImages[1] = ‘adxwide1.png’
theImages[2] = ‘adxwide2.png’
theImages[3] = ‘adxwide3.png’
theImages[4] = ‘adxwide4.png’
theImages[5] = ‘adxwide5.png’
theImages[6] = ‘adxwide6.png’

var j = 0
var p = theImages.length;

var preBuffer = new Array()
for (i = 0; i < p; i++){
preBuffer[i] = new Image()
preBuffer[i].src = theImages[i]
}

var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write(‘<img src=”‘+theImages[whichImage]+'”>’);
}
</script>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@fliptightSep 13.2008 — hello. you should just change the function at the bottom

[CODE]
function showImage(){
document.write('<img src="'+theImages[whichImage]+'">');
}
[/CODE]


to

[CODE]
function showImage(){
document.write('<a href="http://www.addaxtactical.com"><img src="'+theImages[whichImage]+'"></a>');
}
[/CODE]
Copy linkTweet thisAlerts:
@BlackReefDesignauthorSep 13.2008 — sweet! that fixed it, but now there is 2px border around the linked image. How do I set border=0?
Copy linkTweet thisAlerts:
@BlackReefDesignauthorSep 13.2008 — I fixed it! i impress myself sometimes, I know NOTHING about javascript (dont tell my clients!)

var whichImage = Math.round(Math.random()*(p-1));

function showImage(){

document.write('<a href="http://www.addaxtactical.com"><img src="'+theImages[whichImage]+'" [B]border="0"[/B]></a>');

}
×

Success!

Help @BlackReefDesign spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...