| | |
Random Images on Refresh
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 0
" "
I used this code and was able to work it into my site so that my image changes randomly when the page is refreshed. however at this point I want to make the image that is changed, into a link. this is a banner advertisement image on my page and when they click the photo I want people to be able to go to the page that the photo is linking them to. I have made a link there but it is a very small little line, I want it to be the whole picture like I am accustomed to.
•
•
•
•
This script will load random images and they will change when you refresh. I hope this is what you are looking for:
Put in the head:
[html]<SCRIPT LANGUAGE="JavaScript">
var theImages = new Array()
//Random-loading images
theImages[0] = 'images/home_rotate1.gif' // replace with names of images
theImages[1] = 'images/home_rotate2.gif' // replace with names of images
theImages[2] = 'images/home_rotate3.gif' // replace with names of images
theImages[3] = 'images/home_rotate4.gif' // replace with names of images
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(){
if(whichImage==0){
document.write('<a href ="link.html"><img src="'+theImages[whichImage]+'" border=0 width=452 height=181></a>');
}
else if(whichImage==1){
document.write('<a href ="link.html"><img src="'+theImages[whichImage]+'" border=0 width=452 height=181></a>');
}
else if(whichImage==2){
document.write('<a href ="link.html"><img src="'+theImages[whichImage]+'" border=0 width=452 height=181></a>');
}
else if(whichImage==3){
document.write('<a href ="link.html"><img src="'+theImages[whichImage]+'" border=0 width=452 height=181></a>');
}
else if(whichImage==4){
document.write('<a href ="link.html"><img src="'+theImages[whichImage]+'" border=0 width=452 height=181></a>');
}
}
</script>
//Then put this where you want the images to appear:
<script>showImage();</script>[/html]
I used this code and was able to work it into my site so that my image changes randomly when the page is refreshed. however at this point I want to make the image that is changed, into a link. this is a banner advertisement image on my page and when they click the photo I want people to be able to go to the page that the photo is linking them to. I have made a link there but it is a very small little line, I want it to be the whole picture like I am accustomed to.
![]() |
Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: bookmarklet problem
- Next Thread: Detect browser window closing event in Firefox -
Views: 43947 | Replies: 20
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxexample ajaxjspservlets api blackjack browser bug captchaformproblem checkbox child class close cookies createrange() cursor date debugger dependent developer disablefirebug dom dropdown editor element embed engine events explorer ext file flash form forms game gears getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images internet java javascript javascripthelp2020 jquery jsf jsfile jump libcurl maps margin math matrixcaptcha media mp3 mysql object onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php player position post programming progressbar rated runtime safari scriptlets scroll search security session shopping size software solutions star stars stretch synchronous tweet unicode web webkit webservice window wysiwyg \n





