Thanks in advance!!
Random Images On An Html Page
Forum rules
Forum Specific Rules
Forum Specific Rules
So you got questions about audio/video? Wanna know how to rip a digital stream? Make an X/S/VCD to play on your DVD player? Maybe rip a video from VHS or TV? Find the answers here.
-
Leighton
- That Was Just Your Thousandth Post
- Posts: 1963
- Joined: Thu Jan 20, 2005 3:41 am
- Location: In a Snakepit
- Country: Australia
Random Images On An Html Page
I've checked a few sites that try to help out with displaying a random image on a page, but so far I've had no luck. All the places I've seen have said put this text here, this text there, replace the text with your filenames and it'll work. But it ain't happening so far. I'd love just a quick and easy instruction and I hope someone here can help me.
Thanks in advance!!
Thanks in advance!!
NEW WEBSITE UNDER CONSTRUCTION!!
METALLICA, INC.
Last updated 2012-06-28
Leighton Bootlegs*
Last updated 2010-02-26
*Old website
METALLICA, INC.
Last updated 2012-06-28
Leighton Bootlegs*
Last updated 2010-02-26
*Old website
-
Euge
- Trapped Under 800
- Posts: 656
- Joined: Sat Nov 20, 2004 8:35 pm
- Location: Republic of Ireland
- Country: Ireland
Re: Random Images On An Html Page
Code: Select all
<script language="JavaScript"><!--
//Javascript Created by Computerhope http://www.computerhope.com
//store the quotations in arrays
images = new Array(4);
images[0] = "<a href = 'http://www.computerhope.com/index.htm'><img src='http://www.computerhope.com/banners/banner.gif' alt='Visit Computer Hope'></a>";
images[1] = "<a href = 'http://www.computerhope.com/history/index.htm'><img src='http://www.computerhope.com/banners/banner2.gif' alt='Computer History'></a>";
images[2] = "<a href = 'http://www.computerhope.com/index.htm'><img src='http://www.computerhope.com/banners/banner3.gif' alt='Visit Computer Hope'></a>";
images[3] = "<a href = 'http://www.computerhope.com/newslet.htm'><img src='http://www.computerhope.com/banners/banner4.gif' alt='Computer Hope Newsletter'></a>";
index = Math.floor(Math.random() * images.length);
document.write(images[index]);
//done
// --></script><br>-
Leighton
- That Was Just Your Thousandth Post
- Posts: 1963
- Joined: Thu Jan 20, 2005 3:41 am
- Location: In a Snakepit
- Country: Australia
Re: Random Images On An Html Page
Looks like that works. I'll make some new banners and whack them up soon.
NEW WEBSITE UNDER CONSTRUCTION!!
METALLICA, INC.
Last updated 2012-06-28
Leighton Bootlegs*
Last updated 2010-02-26
*Old website
METALLICA, INC.
Last updated 2012-06-28
Leighton Bootlegs*
Last updated 2010-02-26
*Old website
-
frantik2k3
- That Was Just Your Thousandth Post
- Posts: 2330
- Joined: Mon Jun 16, 2003 4:41 am
- Location: New Hampshire, USA
- Country: United States
Re: Random Images On An Html Page
Javascript will get the job done, however, it might fail to work the way you want it to when people view your site using different browsers. You will see a huge difference when viewing your pages in IE and then in FireFox.
Just a heads up on that.
If something breaks in a certain browser, you can usually find a snipbit of code that will correct it. Google is a good source for that stuff.
Just a heads up on that.
If something breaks in a certain browser, you can usually find a snipbit of code that will correct it. Google is a good source for that stuff.
:: Frantik2k3 Trading Website :: hosted by Metpage!
-
Speed Damage
- Phantom Lord
- Posts: 938
- Joined: Tue Apr 01, 2003 12:30 am
- Location: Wisconsin
- Country: United States
Re: Random Images On An Html Page
I think this is pretty much the same as what Euge posted, but I know this worked for me:
(change the file names to you images, thats just what I was using)
save that as a javascript (random.js for example) then just insert that where you want the random image with "<script type="text/javascript" src="random.js">"
Code: Select all
var mess = new Array(
'<img src="banner/banner_01.jpg">',
'<img src="banner/banner_02.jpg">',
'<img src="banner/banner_03.jpg">',
'<img src="banner/banner_04.jpg">',
'<img src="banner/banner_05.jpg">',
'<img src="banner/banner_06.jpg">',
'<img src="banner/banner_07.jpg">',
'<img src="banner/banner_08.jpg">',
'<img src="banner/banner_09.jpg">',
'<img src="banner/banner_10.jpg">');
var max = mess.length;
var num = Math.floor((Math.random() * max));
document.writeln(mess[num]);save that as a javascript (random.js for example) then just insert that where you want the random image with "<script type="text/javascript" src="random.js">"
-
slayerdiabolus
- Stone Cold Poster
- Posts: 3207
- Joined: Sat Oct 30, 2004 8:34 pm
- Location: Cork, Ireland
- Country: Ireland
Re: Random Images On An Html Page
I was asking Spawn the very same question last week. thanks for this!!

2003 - Dublin. 2004 - Donington, Dublin. 2006 - Donington. 2007 - Live Earth, Wembley. 2008 - Dublin, London. 2009 Milan, Rome, Dublin