|
-
Jun 10th, 2002, 12:36 PM
#1
Thread Starter
Addicted Member
changing img's href dynamically
I'm trying to make a dynamic banner generator. Got the images to rotate randomly on a timer (every 10 seconds a new banner pops up) but I also need to change the href of that image to point to a different url every ten seconds. Here's a look at my code... onload calls setBanner and I got some PHP in there.
function setBanner()
{
randomNumber = Math.floor(Math.random()*<?echo($numberBanners);?>);
document.mybanner.src=''+bannerz[4]+'';
setTimeout("pickBanner()", 8000);
}
function pickBanner()
{
randomNumber = Math.floor(Math.random()*<?echo($numberBanners);?>);
document.mybanner.src=''+bannerz[randomNumber]+'';
//document.mybanner.href=''+urls[randomNumber]+'';
window.status = "Banner is now ... "+bannerz[randomNumber];
setTimeout("pickBanner()", 8000);
}
-
Jun 10th, 2002, 01:06 PM
#2
Fanatic Member
Make an onClick command to the image that calls a function like so:
<a href="#" onClick="showURL();"><img src="banner is here"></a>
then in that function check to see which banner element is showing from its array and so the appropriate link that is stored in a different array.
Say banner[4] is showing. So inside your showURL() you would have:
window.open(link[4]);
-Matt
-
Jun 10th, 2002, 01:11 PM
#3
Thread Starter
Addicted Member
gotcha, I had a brain freeze on that... thanks cpradio
-
Jun 10th, 2002, 01:17 PM
#4
Frenzied Member
I think you could also just give your href an id/name and change it's href the same way you changed your image's src.
-
Jun 10th, 2002, 01:20 PM
#5
Fanatic Member
That is a nice idea but I beleive some browsers will not accept that. (For example Netscape)
-
Jun 10th, 2002, 01:22 PM
#6
another possiblity..
I dont know if you can do this with php..
but using asp..I was able to change the content type to an image, and code the asp page to output an image to the Reponse stream..then when you goto the page whatever.asp, it becomes an image, so you could dymacilly have change by coding it in the asp page then in the img tage use
src="yourpage.asp"
again I dont know how in php if it is possible.
just some FYI
-
Jun 10th, 2002, 01:25 PM
#7
fdor example..see my banner in my sig..if you notice..the text changes when you refresh the page..and if you were to look at the link..you would see a .aspx extension(ASP .NET)..and it uses the technique i described.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|