Drummy's Random Image Script Wizard
What is this?
This JavaScript will allow you to display one of several images on your website/forum/whatever.Usage?
You enter the URLs of the images the script should choose from in the forum below. Then the Drummy Script Wizard gives you the complete code that you need with all instructions. Simple as that! Good or what? If you like it, please consider donating me a buck or two :)Price?
FREE! But if you like it, you can donate a buck or two towards my further work here. :)In order to get the code you need, simply enter the complete URLs (including http://) in the text-box below, one address per line.



January 19th, 2007 at 23:12
you’re missing two closing parentheses in the document.write part. other than that, works beautifully. thanks dude.
January 19th, 2007 at 23:19
Hi Jessica,
thanks for the hint, I’ve updated the code now.
And thanks for using the code
January 22nd, 2007 at 07:54
Hey everything looks good. Im not really that experienced with implementing javascript, but I was wondering how do I implement it in the html? know where to put the actual javascript (Im actually linking it externally) but whats the way to reference wherever your’re placing it in the html?
January 22nd, 2007 at 11:16
Hi Alex,
thanks for visiting
Just place this code where you want the random image to appear, it’s as simple as that.
and .So basically anywhere between
I’ll be reworking the script to make it a little prettier. You will have one section to put between and and then one small line of code which you put where the random image should appear.
If you have any more questions, go ahead and ask or e-mail me: email@drummy.org
January 22nd, 2007 at 12:14
I’ve just gone and done it!

February 17th, 2007 at 17:32
Nice, nice, nice just doing the trick, works fine, integrates fine in complexe site
February 17th, 2007 at 18:00
Glad you like it
February 24th, 2007 at 19:37
Man thanks fot this wonderful script!! Good work! Keep it on !
February 24th, 2007 at 19:41
Thanks Cristi, your complement is much appreciated!
March 11th, 2007 at 12:12
wonderful, just what i was looking for thanks!
March 11th, 2007 at 12:23
Glad to help
April 3rd, 2007 at 17:45
Is there a way I can add a specific link to each image?
April 3rd, 2007 at 19:18
Hi Yum,
yes sure. Would you want to add one specific link any time a random image is displayed? Or do you want a different link for each image?
If it’s just one link you want to display, it’s simple.
Run the wizard on this page and enter the image URLs.
Then follow step 1.
In step two instead of
use:
Of course you replace http://yourlink.com with the link you need.
If you need a different link for each image, let me know. Use the contact form on this site to send me the images and the links and I’ll write you the code.
April 3rd, 2007 at 20:06
Hi Drummy yes I need a different link for each image displayed. Thanks for the help
April 3rd, 2007 at 20:07
i’m just on the testing phase so go ahead and use dummy links for now…thanks.
April 3rd, 2007 at 21:02
Hi again Yum,
I’ve put it on a seperate HTML page to make it easier (for me AND you lol).
Check it out:
http://www.drummy.org/picswithlinks.html
If there’s anything that you don’t understand, let me know.
April 3rd, 2007 at 21:08
thank you i’ll give it a shot…looks easy enough
May 28th, 2007 at 06:57
How can you make this work using the javascript unobtrusively? Separating it out of the HTML, and instead calling it in the head of the document
Then calling it up in the body of the HTML page in one line. But what would the command be to call it into the page body?
I can’t figure it out.
May 29th, 2007 at 02:17
I’m not sure exactly what you mean. Can you give me an exmaple of what you’re talking about?
June 16th, 2007 at 06:23
I’m trying to use this script on mutiple pages, and have them all have the same images, and allow the images to be easily changed. So I created an external .js file, and linked the script in the html files correctly, but I can’t seem to get it to work, do you have any sugguestions?
June 16th, 2007 at 06:30
o nvm I got it
June 16th, 2007 at 14:08
Glad you’ve worked it out.
June 24th, 2007 at 12:09
Thank you very much for this - it’s great, just what I was looking for!
July 5th, 2007 at 12:11
Hi,
Is there a way to modify this script a bit to shows several random images on 1 page at the same time without repeat?
July 5th, 2007 at 12:18
Sure. If you’d consider a small donation, I’d be happy to adjust the script accordingly.
Jet let me know how many instances of the script you need (how many multiple images) and the URLs of the images you want to use.
July 5th, 2007 at 12:18
PS: you can use the contact form to contact me.
July 12th, 2007 at 01:43
Thanks dude, works awsome.
August 7th, 2007 at 14:48
Thanks dude, it helped me to put a image gallery on sharepoint.
i changed it a lil to get text on my image
Imgtxt[1] = “This is a test”;
document.write(”");
document.write(Imgtxt[whichImg]);
var Imgtxt=new Array(7)
ur code helped a lot, thanks againn
August 7th, 2007 at 18:41
Hey abgary,
glad to have helped.
August 8th, 2007 at 12:07
Hi there…
Just wondering if you ended up adjusting the script so that it can be used a few time on the same page… I’ve tried but to no avail. I’d like to use say three different directories, each with say 3 images.
Cheers,
Dylan
August 8th, 2007 at 13:15
Yes, I have done that for a project of mine. I don’t have the code anymore, but I’m sure I could do it again.
E-mail me the URLs of the three image sets and I’ll get it sorted.
November 14th, 2007 at 18:39
Will this allow me to randomize a slideshow? Or is this just for individual images?
I have about 35 pictures that my boss wants me to put into a randomized slideshow on our homepage. Right now, we have about 20 images on a non-randomized slideshow, but no one ever looks at that particular page for longer than a minute or two. So I’d like to be able to randomize the slideshow so that every time someone goes to our homepage, they see a different slide show. Is that what this code will do?
November 14th, 2007 at 18:43
Nope. This one displays individual images randomly. For what you’re looking for, I’d probably go with using Flash or JavaScript / DHTML.
December 28th, 2007 at 07:36
First of all, thanks for this great script. It works great!
Second, I was wondering if there was a way to randomize the same pictures using different layers on the same html page. For instance, someone goes to the website and they see one picture. They click on a tab to unhide another layer and a different picture is displayed from the same originally picked pics. Additionally, whenever a user clicks on a tab or a created hotspot which unhides a layer, a new randomized picture is displayed. Is this possible?
Thanks again for the great script as it is now
January 26th, 2008 at 04:26
oops…the code got all screwy:
elseif ($this_is_home_page) //home page
{
echo "";
}
?>
January 26th, 2008 at 10:32
You can implement it real easy. Just put it into the echo “”; statement.
Like this:
echo "<script….";
Just make sure that you escape any double-quotes, so it looks a little like this:
echo "<script language=\"JavaScript\">…";
see what I mean? If it doesn’t work out, e-mail me through the contact form.
January 28th, 2008 at 02:40
Hey Thanks for the script it works great. I was interested in making the images printable. What would i need to add to the script and where to make each random image have the option of being printed when clicked?
January 28th, 2008 at 20:32
Hm. I’m not too familiar with printing via JavaScript. But if you contact me this weekend (because otherwise, I’ll forget), I’ll look into it and see what I can do.
January 30th, 2008 at 22:12
thanks let me know if you can help
February 1st, 2008 at 19:20
Hi Alex,
I have found something. Not tested though.
First, add the following code between <head> and </head>:
<script>
function makepage(src)
{
// We break the closing script tag in half to prevent
// the HTML parser from seeing it as a part of
// the *main* page.
return "<html>\n" +
"<head>\n" +
"<title>Temporary Printing Window</title>\n" +
"<script>\n" +
"function step1() {\n" +
" setTimeout(’step2()’, 10);\n" +
"}\n" +
"function step2() {\n" +
" window.print();\n" +
" window.close();\n" +
"}\n" +
"</scr" + "ipt>\n" +
"</head>\n" +
"<body onLoad=’step1()’>\n" +
"<img src=’" + src + "’/>\n" +
"</body>\n" +
"</html>\n";
}
function printme(evt)
{
if (!evt) {
// Old IE
evt = window.event;
}
var image = evt.target;
if (!image) {
// Old IE
image = window.event.srcElement;
}
src = image.src;
link = "about:blank";
var pw = window.open(link, "_new");
pw.document.open();
pw.document.write(makepage(src));
pw.document.close();
}
</script>
Then, in every <img src…> add this bit:
onClick="printme(event)"
That should do the trick. But as I said, I haven’t tested this.
February 27th, 2008 at 00:22
Hi,
I am looking around, without success since now, to find a script for random images from a file, just naming the file, and NOT the pictured in it…
It seems you are almost expert on such questions…
would it be possible to help me?
Thanks in advance
Emilio
February 27th, 2008 at 09:40
It must be possible to do, using AJAX. But I am far from an expert in that field. If I would want something like that, I would probably use PHP to do it, because I know my way around PHP way better.
April 6th, 2008 at 06:34
Did you ever make the script for multiple random images? I’d like to display 6 images from a list of about 10 or 12… in TD table cells with text underneath… and links. :-)
if i had a basic script i could make it work in the setup I need. I just can’t find how to not duplicate a photo once it’s used once.
how much? lol paypal?
April 6th, 2008 at 11:43
Yeah I made a script with several instances of the random image. So I could make it again.
As for how much (lol) - you decide. I don’t ask for money for my script (or reasonable modifications of it), but anyone that uses it may want to donate whatever amount they see fit.
Did I understand you correctly, you want to have one set pool of random images and then you want 6 instances of the script to display a random image from that set pool of images. Is that correct?
Send me your image URLs via the contact form and I’ll take it from there.
April 23rd, 2008 at 22:00
hi Drummy
was just wondering how to set a specific size for all the images without making all the images actually that size
thanks
April 23rd, 2008 at 22:06
This script is great!
I’d like to add a link to one image but I have all of my images locally as opposed to pointing to them on a website. How would I add the link?
Thanks!
var img=new Array(4)
img[0]=”images/index/top_prweek.jpg”;
img[1]=”images/index/top_sabre.jpg”;
img[2]=”images/index/top_impact.jpg”;
img[3]=”images/index/top_coynexchange.jpg”; >>
April 23rd, 2008 at 22:13
Sorry - that last img I want to go to the link http://coynexchange.com in a new window
April 23rd, 2008 at 23:03
Hi nick and Shawn - I’m extremely busy right now and likely to forget your questions, lol.
Could you guys please use the contact feature and send them to me that way?
That way they land in my mailbox and I won’t forget them.
October 7th, 2008 at 21:58
Hey first off thanks for the great script it works great. I was just what I needed for my site. Now I have a quick question I noticed in the scripted that there’s a place to set a border. I set it to 1px and it works great on safari and Firefox, but has no luck with IE. Is there any way I can add a border to this that’ll make it work with IE? I really don’t want to have to put a border on every image I have when I could maybe do it in the code. If you could help me out with this that would be great. Thanks for the help.
October 7th, 2008 at 23:58
Sure, just use CSS. Replace this:
border=’0′
With this:
style=’border:1px solid;’ or something along the lines. Play around with it, till you like it.
October 9th, 2008 at 17:15
Nice thanks ya style css code did the trick. For some reason I had to change the apostrophe to one that wasn’t curved which i thought was weird lol. Thanks again for help.