Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old September 13th, 2008, 12:02 AM   #1
WebForumz Member
 

Join Date: Jun 2007
Location: San Diego/RC
Age: 25
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 BlackReef is on a distinguished road
How do I attach a URL link to Images in a Javascript?

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?

Thanks

Here is the code:

HTML Code:
<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>

Last edited by Aso; September 13th, 2008 at 12:21 PM..
BlackReef is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 13th, 2008, 09:25 AM   #2
New Member
 

Join Date: May 2007
Location: Sendai, Japan
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 BonRouge is on a distinguished road
Re: How do I attach a URL link to Images in a Javascript?

Change this:
Code:
document.write('<img src="'+theImages[whichImage]+'">');
to something like this:
Code:
document.write('<a href="index.htm"><img src="'+theImages[whichImage]+'"></a>');
(Put the image in a link).
BonRouge is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Link to another page in JavaScript R8515198 JavaScript 12 January 30th, 2008 02:08 PM
Attach sound file to Javascript rollover popup supanova75 JavaScript 1 October 4th, 2007 10:47 AM
Forcing JavaScript to load before images? JennyChaos Your Design and Layout 14 July 13th, 2007 07:02 PM
How to attach route planner R8515198 HTML, XHTML and CSS 0 May 11th, 2007 04:03 PM
Can you link in .asp files like you can .css and Javascript? Andy K Classic ASP 2 July 13th, 2005 06:13 AM


Search Engine Optimization by vBSEO 3.2.0 RC8