Register | Login | |||||
Main
| Memberlist
| Active users
| ACS
| Commons
| Calendar
| Online users Ranks | FAQ | Color Chart | Photo album | IRC Chat |
| |
0 user currently in Programming. | 3 guests |
Acmlm's Board - I2 Archive - Programming - Random images in HTML | | | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread |
User | Post | ||
alitnil Snifit Level: 27 Posts: 120/290 EXP: 107568 For next: 8591 Since: 07-16-04 From: Phoenix, AZ Since last post: 56 days Last activity: 44 days |
| ||
how would I code for an image that is randomized each time you visit or refresh the page in HTML terms? | |||
Modereb Paragoomba Level: 15 Posts: 42/75 EXP: 14749 For next: 1635 Since: 06-04-04 Since last post: 350 days Last activity: 339 days |
| ||
You can't with just HTML, you either have to use Javascript, or a server side language such as ASP or PHP. Examples that will output image0.jpg, image1.jpg or image2.jpg... Javascript: document.write('<img src="image'+Math.floor(Math.random()*3)+'.jpg" alt="image" />'); PHP: <? echo "<img src=\"image".rand(0,2).".jpg\" alt=\"image\" />"; ?> ASP <% randomize randnumber=int(rnd*2)+0 response.write randnumber %> (edited by Modereb on 09-21-04 02:07 AM) |
|||
Zem You can be civil without being flowery, dipshits. Level: 49 Posts: 142/1107 EXP: 829398 For next: 54485 Since: 06-13-04 Since last post: 131 days Last activity: 131 days |
| ||
For PHP, it's more common to link to an image.php, so you can do it on servers you don't control.<?php Of course, you probably don't have access to a php server. In which case you'd have to do the Javascript one, which this board wouldn't allow you to do. |
|||
alitnil Snifit Level: 27 Posts: 122/290 EXP: 107568 For next: 8591 Since: 07-16-04 From: Phoenix, AZ Since last post: 56 days Last activity: 44 days |
| ||
Modereb, I'll go with the Javascript, but surprisingly enough, I am confused (shocker). document.write(''); the image src= section, that is where i would type out the file location correct? as in http://www.website.com/file? |
|||
Modereb Paragoomba Level: 15 Posts: 46/75 EXP: 14749 For next: 1635 Since: 06-04-04 Since last post: 350 days Last activity: 339 days |
| ||
If you put this in a HTML file: <script type="text/javascript"> document.write('<img src="random_image'+Math.floor(Math.random()*3)+'.jpg" alt="image" />'); </script> Either <img src="random_image0.jpg" alt="image" />, <img src="random_image1.jpg" alt="image" /> or <img src="random_image2.jpg" alt="image" /> is outputted by the Javascript. So, basically, just paste that code anywhere where you want to have the random image in your HTML file, and make sure the images random_image0.jpg, random_image1.jpg and random_image2.jpg are there. |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread |
Acmlm's Board - I2 Archive - Programming - Random images in HTML | | | |