We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
  • Pages:
  • 1
Random Image HTML
Topic Started: Jun 10 2005, 08:23 PM (2,527 Views)
Captain Kam
Custom member title
[ *  *  *  *  * ]
Hey, I'm in need of the code that loads random images per view, like;

Say you have five images that you put on a website, and want to load them at random.

On one pageview, it could be image4. On another, it could be image1. Get what I'm saying? ^_^'

So, does anybody know this bit of HTML?

Edit:

Ehh, I think I put this in the wrong forum. o_O' Did I?
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
Nope, this is fine.

http://www.alistapart.com/articles/randomizer/
Offline Profile Quote Post Goto Top
 
Captain Kam
Custom member title
[ *  *  *  *  * ]
Thanks. :3
Offline Profile Quote Post Goto Top
 
solinent
Member Avatar
Member
[ *  *  * ]
It would be a whole lot easier to do with javascript...

<script language="javascript">
var num = Math.Rand() * 10;
if (num == 1) {
document.write("<img src='path/to/first/image.png' />");
}
if (num == 2) {
document.write("<img src='path/to/second/image.png' />");
}
</script>

That'll do two imgages, just add as you go along....it's so simple...
Offline Profile Quote Post Goto Top
 
Stefan
Member Avatar
Mew?
[ *  *  *  *  *  *  * ]
solinent
June 13, 2005 04:23 AM
It would be a whole lot easier to do with javascript...

<script language="javascript">
var num = Math.Rand() * 10;
if (num == 1) {
document.write("<img src='path/to/first/image.png' />");
}
if (num == 2) {
document.write("<img src='path/to/second/image.png' />");
}
</script>

That'll do two imgages, just add as you go along....it's so simple...

:ph34r:

Code:
 
<script type='text/javascript'>
n = 0;
rndImages =[];
rndImages[n++] = 'http://host.com/image1.jpg';
rndImages[n++] = 'http://host.com/image2.jpg';
rndImages[n++] = 'http://host.com/image3.jpg';
rndImages[n++] = 'http://host.com/image4.jpg';

document.write('<img src="'+rndImages[Math.floor(Math.random() * n)]+ '" alt="" />');
</script>


But if your server supports it, PHP is a better choice :yes:
Look! Semicolons!
Offline Profile Quote Post Goto Top
 
solinent
Member Avatar
Member
[ *  *  * ]
I use asp on my site :) for a random quote :)
Offline Profile Quote Post Goto Top
 
Luke6006
Member
[ *  *  *  *  *  *  * ]
I don't mean to bump this topic much, but I'm wondering how would this work? You wouldn't be able to use a .html for an image.
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
No, you just put the code Stefan posted in the html of the website.
So something like:
Code: HTML
 
<body>
Some text.<br />
More text ^^ <br />
The next line has a random image<br />
<script type='text/javascript'>
n = 0;
rndImages =[];
rndImages[n++] = 'http://host.com/image1.jpg';
rndImages[n++] = 'http://host.com/image2.jpg';
rndImages[n++] = 'http://host.com/image3.jpg';
rndImages[n++] = 'http://host.com/image4.jpg';

document.write('<img src="'+rndImages[Math.floor(Math.random() * n)]+ '" alt="</span>" />');
<[color=blue]/script>
<br />
It was done with JS.


Stefan
 
Look! Semicolons!

:o


*<span style='color:red'>Qj[/color] wonders if bringing a topic back up by giving an awnser there is bad :unsure:
Offline Profile Quote Post Goto Top
 
Luke6006
Member
[ *  *  *  *  *  *  * ]
Qj
June 18, 2005 12:02 PM
*Qj wonders if bringing a topic back up by giving an awnser there is bad  :unsure:

I wouldn't have thought so.
Let me get this right, you just make a html document and put it as an image into the box?
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
Just paste the code into the html document where you want the random img, yes.
Offline Profile Quote Post Goto Top
 
Luke6006
Member
[ *  *  *  *  *  *  * ]
I don't think you're understand what I mean, :no: , I mean I want something to run off my webserver which has no extensions installed to use as an image rotator but I can't put a .html file as an image.
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
You don't have to use a .html as an image.
You just put that code where you want the image.
I could even put it here (If I could use the [doHTML ] tag/code that is :P )
So you can use this anywhere (almost anyway).
Offline Profile Quote Post Goto Top
 
Luke6006
Member
[ *  *  *  *  *  *  * ]
How would I use it in my signature then? (not for here) What code would it be?

edit:
Sorry, it should just go in the img tags. :$
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
If you can use html in your sig, just put the code right there in your sig.
If you can't use html in your sig, you can't use it (As far as I know anyway)
(You can't use a php as an image source on any IF board, can you?)

And doesn't this fall under this verry sticky topic and the lines above all topics/topic index in this forum?? :unsure:
Offline Profile Quote Post Goto Top
 
Luke6006
Member
[ *  *  *  *  *  *  * ]
Yeah, but it's not really just for invisionfree it's for all the forums (even if they're not powered by invision).
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · Technology Chat · Next Topic »
Add Reply
  • Pages:
  • 1