Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

javascript - link images to web link

Firstly, I am not a web designer and I have very limited knowledge of html, css, javascript etc.

I am running a script which displays a random image each time the page is refreshed. I would like to know, how I can set a click through link that allows the user to click on the random image and follow through to another web page.

The script im using is below. Ideally, I'd like to be able to click on the image and then be sent to a definition of the word.

For example, when "expose.png" is shown, id like to be able to click on the image and be taken to, http://oxforddictionaries.com/definition/english/expose?q=expose

please help.

<a href="javascript:document.location.reload();"
ONMOUSEOVER="window.status='Refresh'; return true">
<img src="Graphic-design-can-[TEST].png" width="auto" height="auto"//>
</a>

</div>




<div id="outcome">

<script language="JavaScript">

function random_imglink(){
var myimages=new Array()

myimages[1]="expose.png"
myimages[2]="inform.png"
myimages[3]="explain.png"
myimages[4]="formulate.png"
myimages[5]="record.png"
myimages[6]="mediate.png"
myimages[7]="design.png"
myimages[8]="persuade.png"
myimages[9]="summarise.png"
myimages[10]="generate.png" 


var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0>')
}
random_imglink()

</script>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can do like this...

</div>




<div id="outcome">

<script language="JavaScript">

function random_imglink(){
var myimages=new Array()

var mylink=new Array()

myimages[1]="expose.png"
mylink[1]="www.atrein.com"
myimages[2]="inform.png"
mylink[2]="www.atrein.ir"
myimages[3]="explain.png"
mylink[3]="www.apadana-business.com"
myimages[4]="formulate.png"
mylink[5]="www.google.com"



var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<a href="'+mylink[ry]+'" ><img src="'+myimages[ry]+'" border=0> </a>')
}
random_imglink()

</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...