Current location: Hot Scripts Forums » General Web Coding » JavaScript » add link to image...


add link to image...

Reply
  #1 (permalink)  
Old 02-19-09, 09:54 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
add link to image...

Hi there..

I got these lines of html:

HTML Code:
<tr>
       <td id="item1" style="background-color:#141414;" class="active" onclick="ClickNr('item1',0);" onmouseover="OverNr('item1')" onmouseout="TerugNr('item1')" >1</td>
       <td id="item2" style="background-color:#000000; border-left:1px solid #666666;" class="inactive" onclick="ClickNr('item2',1);" onmouseover="OverNr('item2')" onmouseout="TerugNr('item2')" >2</td>
       <td id="item3" style="background-color:#000000; border-left:1px solid #666666;" class="inactive" onclick="ClickNr('item3',2);" onmouseover="OverNr('item3')" onmouseout="TerugNr('item3')" >3</td>
       <td id="item4" style="background-color:#000000; border-left:1px solid #666666;" class="inactive" onclick="ClickNr('item4',3);" onmouseover="OverNr('item4')" onmouseout="TerugNr('item4')" >4</td>
</tr>
<tr>
       <td id="berichten" class="berichten" colspan="4"><img id="banner_img" src="images/banner/banner1.jpg" width="300px" height="74px" border="0" style="cursor:pointer;" /></td>
</tr>
in this javascript the banners change each 5 seconds and after click in one of the <td> above the banner...

Code:
var banners = new Array("images/banner/banner1.jpg","images/banner/banner2.jpg","images/banner/banner3.jpg","images/banner/banner4.jpg");
var linked = new Array("http://www.nu.nl","http://www.startpagina.nl","http://www.msn.com","http://www.google.nl");

var loop_pause = 4000;
var click_pause = 0000;
var looop;
var NrItem;
function ChooseNr(tagtog){
   for(var i=1;i<=4;i++){
      document.getElementById('item'+i).className = 'inactive';
      document.getElementById('item'+i).style.backgroundColor = '#000000';
   }
   document.getElementById(tagtog).className = 'active';
   document.getElementById(tagtog).style.backgroundColor = '#141414';
   if(tagtog == 'item1'){
      document.getElementById("banner_img").src = banners[0];
      looop=setTimeout('ChooseNr("item2")', loop_pause);
   }
   else if(tagtog == 'item2'){
      document.getElementById("banner_img").src = banners[1];
      looop=setTimeout('ChooseNr("item3")', loop_pause);
   }
   else if(tagtog == 'item3'){
      document.getElementById("banner_img").src = banners[2];
      looop=setTimeout('ChooseNr("item4")', loop_pause);
   }
   else if(tagtog == 'item4'){
      document.getElementById("banner_img").src = banners[3];
      looop=setTimeout('ChooseNr("item1")', loop_pause);
   }
}
function ClickNr(i,v){
   clearTimeout(looop);
   NrItem=i;
   document.getElementById("banner_img").src = banners[v];
   looop=setTimeout('ChooseNr(NrItem)', click_pause);
}
How can I add a link (in the array linked) to the different images?.. So when image 1 is displayed link 1 must be connected to that.


_j
Reply With Quote
  #2 (permalink)  
Old 02-19-09, 09:58 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Quick sample for one of your banners:

Code:
if(tagtog == 'item1'){
      document.getElementById("banner_img").src = banners[0];
      document.getElementById("banner_img").onclick = "window.open(linked[0], "myWindow");";
      document.getElementById("banner_img").style.cursor=pointer;
      looop=setTimeout('ChooseNr("item2")', loop_pause);
   }
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
  #3 (permalink)  
Old 02-20-09, 02:09 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
thnx yeroon...

but it's not working yet...


Got is like this now:

Code:
var linked = new Array("http://www.nu.nl","http://www.startpagina.nl","http://www.msn.com","http://www.google.nl");
document.getElementById("banner_img").onClick = 'window.open(linked[0], "myWindow");';
HTML Code:
<img id="banner_img" src="images/banner/banner1.jpg" width="300px" height="74px" border="0" style="cursor:pointer;" />
the link is not attached to the banner...

_j
Reply With Quote
  #4 (permalink)  
Old 02-20-09, 03:21 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
And like this?

Code:
var linked = new Array("http://www.nu.nl","http://www.startpagina.nl","http://www.msn.com","http://www.google.nl");
document.getElementById("banner_img").onClick = function() {openWin(linked[0]);};
Add function to javscript section:

Code:
function openWin(link){
  window.open(link, 'MyWin');
  
}
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
Reply

Bookmarks


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

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add url to the image Nikas JavaScript 5 01-30-09 04:25 PM
div css theighost CSS 11 09-14-08 02:30 AM
Six Sites Exchanging Links! - PR3+ Web Hosting, Web Design, Entertainment & Career coffeecoder General Advertisements 0 10-10-05 12:52 AM
Making a flash image a link Balkee867 Flash & ActionScript 4 08-02-05 04:10 PM
Xml / Dom / Css Mark_SC.SE JavaScript 0 06-29-05 08:05 AM


All times are GMT -5. The time now is 11:45 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.