943,704 Members | Top Members by Rank

Ad:
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Sep 1st, 2006
0

Re: Random Images on Refresh

you should change the links as well
Reputation Points: 10
Solved Threads: 1
Newbie Poster
elie is offline Offline
2 posts
since Jul 2006
Apr 2nd, 2007
0

Re: Random Images on Refresh

Click to Expand / Collapse  Quote originally posted by ANH! ...
Wow thanks, a code that actually works... but I still have a problem/query...

Is there any way that in 4 refreshes every image is shown once?

Dont think I can explain much more...

Thanks for any help in advance.
Click to Expand / Collapse  Quote originally posted by raywood5 ...
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]

Is there a way to do this multiple times on one page??
Reputation Points: 10
Solved Threads: 1
Newbie Poster
graphic_cre8or is offline Offline
1 posts
since Apr 2007
Feb 14th, 2008
0

Re: Random Images on Refresh

I would like to have a similar script that would pull images directly from a folder of images. I'll have over 200 of these images and would like a different on to be displayed when the browser is refreshed. Any ideas? The Rookie Webmaster. Thanks in advance for your time.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
seakins is offline Offline
1 posts
since Feb 2008
Apr 18th, 2008
0

Re: Random Images on Refresh

Please edit the image size of your random images in script you put it in head part
Reputation Points: 10
Solved Threads: 1
Newbie Poster
anandgiri is offline Offline
1 posts
since Apr 2008
May 27th, 2008
0

Re: Random Images on Refresh

Many thanks for this, I know its an old thread, but Google found it, and its exactly what I need!
Reputation Points: 49
Solved Threads: 11
Posting Whiz in Training
uniquestar is offline Offline
239 posts
since Feb 2005
Jun 21st, 2008
0

Re: Random Images on Refresh

Is it possible for this to be insearted into a phpbb3 forum headder?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mspedd is offline Offline
1 posts
since Jun 2008
Sep 11th, 2008
0

Re: Random Images on Refresh

Lets say you wanted to have two images on the page change at the same time... and the images related to each other so that ....

When showImage loads you have a 2nd image location on the page that goes along with it.

I'm trying to make it so that the leftcolumn and rightcolumn of my page change insync with each other but at random.

I'm just learning javascript but think I understand the logic needed.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jasonbender is offline Offline
1 posts
since Sep 2008
Sep 12th, 2008
0

Re: Random Images on Refresh

are you looking for something like this? http://www.amerimod.com/
Reputation Points: 10
Solved Threads: 1
Newbie Poster
raywood5 is offline Offline
10 posts
since Jan 2005
May 26th, 2009
0

Re: Random Images on Refresh

Hi I am looking for something similar but for website background image. I have 3 images that cover the whole browser and I want them to rotate when some hits refresh on the browser. Can anyone help me on this thanks.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JimPatrick is offline Offline
7 posts
since May 2009
Oct 3rd, 2009
0

Re: Random Images on Refresh

Lets say you wanted to have two images on the page change at the same time... and the images related to each other so that ....

When showImage loads you have a 2nd image location on the page that goes along with it.

I'm trying to make it so that the leftcolumn and rightcolumn of my page change insync with each other but at random.

I'm just learning javascript but think I understand the logic needed.
slightly modified version of the same code to get two images that are linked to show up:

JavaScript Syntax (Toggle Plain Text)
  1. <SCRIPT LANGUAGE="JavaScript">
  2. var theImages = new Array()
  3. theImages[0] = 'Picture_Index_Left_Rotate_1.jpg'
  4. theImages[1] = 'Picture_Index_Left_Rotate_2.jpg'
  5. theImages[2] = 'Picture_Index_Left_Rotate_3.jpg'
  6. theImages[3] = 'Picture_Index_Left_Rotate_4.jpg'
  7. theImages[4] = 'Picture_Index_Left_Rotate_5.jpg'
  8.  
  9. var j = 0
  10. var p = theImages.length;
  11. var preBuffer = new Array()
  12.  
  13. var whichImage = Math.round(Math.random()*(p-1));
  14.  
  15. function showImage(){
  16. if(whichImage==0){
  17. document.write('<img src="Picture_Index_Left_Rotate_1.jpg" width="407" height="336" border="0" />');
  18. }
  19. else if(whichImage==1){
  20. document.write('<img src="Picture_Index_Left_Rotate_2.jpg" width="407" height="336" border="0" />');
  21. }
  22. else if(whichImage==2){
  23. document.write('<img src="Picture_Index_Left_Rotate_3.jpg" width="407" height="336" border="0" />');
  24. }
  25. else if(whichImage==3){
  26. document.write('<img src="Picture_Index_Left_Rotate_4.jpg" width="407" height="336" border="0" />');
  27. }
  28. else if(whichImage==4){
  29. document.write('<img src="Picture_Index_Left_Rotate_5.jpg" width="407" height="336" border="0" />');
  30. }
  31.  
  32. }
  33.  
  34. function showImage2(){
  35. if(whichImage==0){
  36. document.write('<img src="Picture_Index_Right_Rotate_1.jpg" width="518" height="336" />');
  37. }
  38. else if(whichImage==1){
  39. document.write('<img src="Picture_Index_Right_Rotate_2.jpg" width="518" height="336" />');
  40. }
  41. else if(whichImage==2){
  42. document.write('<img src="Picture_Index_Right_Rotate_3.jpg" width="518" height="336" />');
  43. }
  44. else if(whichImage==3){
  45. document.write('<img src="Picture_Index_Right_Rotate_4.jpg" width="518" height="336" />');
  46. }
  47. else if(whichImage==4){
  48. document.write('<img src="Picture_Index_Right_Rotate_5.jpg" width="518" height="336" />');
  49. }
  50.  
  51. }
  52.  
  53. </script>

after this use
<script>showImage();</script> and <script>showImage2();</script>
where you need the image to show up in the body
(note - took out link so if you need it to link add the <a href> tag)
Also - the images are called staticly...so no need for the i variable here
Last edited by peter_budo; Oct 4th, 2009 at 7:48 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
AJ-
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AJ- is offline Offline
1 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Validating a file input inside an iframe
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Jquery Ajax GET Problem!!!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC