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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add link to this script

Status
Not open for further replies.

SjrH

IS-IT--Management
Joined
Jun 24, 2003
Messages
747
Location
GB
How easy would it be to add a link variable to this script so that when clicked on it would open up a new window relevant to that image?

Code:
image = new Array

image[1]="images/article1.gif"
image[2]="images/article2.gif"
image[3]="images/article3.gif"
image[4]="images/article4.gif"
image[5]="images/article5.gif"

random_num = (Math.round((Math.random()*4)+1))

document.write("<img src=\"" + image[random_num] + "\">");

Its probably quite simple i'm sure! The image display has worked well but it would be nice to be able to navigate to a page with it as well!

Thanks
 
you can try...

Code:
document.write("<a target=\"_blank\" href=\"" + image[random_num] + "\">Link To Image " + random_num + "</a>");



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thanks for that :)

I was trying to achieve the opposite result tho - get the image link to point to a page in a new document as opposed to point to the source of the image.

Your code gave me an idea so I have used this which seems to do what I want...

Created another array containing
docref[x]="URL" where x is the relavant image number for the document

Code:
document.write("<a target=\"_blank\" href=\"" + docref[random_num] + "\"><img src=\"" + image[random_num] +"\" border=\"0\"></a>");

This is a whole new world for me so I guess i'll just plod along picking things up slowly!

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top