Is there such thing as a random image script that can work along side mootools?
Thanks,
John
Is there such thing as a random image script that can work along side mootools?
Thanks,
John
A 'random image script' isn't very specific. And I'm not sure what you mean by 'along side', though that would literally mean on the same page as mootools, but without using mootools.
The answer in any case though is yes. There are scripts where random images are involved that can work on a page that also has mootools installed. There probably are even mootools based random image scripts.
What exactly did you have in mind? Do you have a random image script that does what you want but just doesn't work on a page with mootools?
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
This:
I have a random image script that does what you want but just doesn't work on a page with mootools.
What are some solutions?
Or you guys can suggest me one that already works along side mootools.PHP Code:<script language="JavaScript">
<!--
function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="image1.gif"
myimages[2]="image2.gif"
myimages[3]="image3.gif"
myimages[4]="image4.gif"
myimages[5]="image5.gif"
myimages[6]="image6.gif"
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0>')
}
random_imglink()
//-->
</script>
It appears that that script will only show an image if the random number equals 0. Try:
Code:<script type="text/javascript"> var myimages = new Array(); myimages[0]="image1.gif" myimages[1]="image2.gif" myimages[2]="image3.gif" myimages[3]="image4.gif" myimages[4]="image5.gif" myimages[5]="image6.gif" var randomImg = function(){ var random = Math.floor(Math.random()*myimages.length); document.write('<img src="'+myimages[random]+'" border=0>'); }; </script>
Jeremy | jfein.net
Although the code for the random image script is questionable IMO, too exposed, sloppy, and uses document.write unnecessarily, it does work here with mootools in IE 7 and Firefox 3.5:
What browser are you using?Code:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js"></script> <script type="text/javascript"> var myimages = new Array(); myimages[0]="image1.gif" myimages[1]="image2.gif" myimages[2]="image3.gif" myimages[3]="image4.gif" myimages[4]="image5.gif" myimages[5]="image6.gif" var randomImg = function(){ var random = Math.floor(Math.random()*myimages.length); document.write('<img src="'+myimages[random]+'" border=0>'); }; </script> </head> <body> <script type="text/javascript"> randomImg(); </script> </body> </html>
If you want more help:
Please post a link to the page on your site that contains the problematic code so we can check it out.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
If you have PHP, you could use that to open the folder that has the images in it and fetch all the files in that folder that are images by testing their extensions. But this requires a PHP enabled server, and will not work if the opendir and/or readdir functions are disabled as is sometimes the case. It also won't work locally unless you have a a local PHP sandbox of some kind to test it in. But if your server does have PHP with those functions enabled, the whole thing could be done in PHP. Even without those functions, this all PHP script would work on a PHP enabled server:
http://www.totallyphp.co.uk/scripts/random_image.htm
But you would have to setup the filenames in a certain way and configure in the script how many there are, their extension, etc.
But with those functions, files of any extension(s) that you choose (like .jpg, .gif, .png, .jpeg, etc. - upper and lower case) could be fetched and their names wouldn't matter.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Bookmarks