Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
a Summer night - @248.78
Activity rating: Four Stars Posts & Arts: 53/1k.beats ~ Boop! The forum will close in 752.beats! Random | Recent Posts | Guild Recents
News: It's the silly things you'll remember :trash: Guild Events: Summer Projects

+  MelonLand Forum
|-+  Life & The Web
| |-+  ✁ ∙ Web Crafting
| | |-+  Randomized elements that change upon refresh?


« previous next »
Pages: [1] Print Embed
Author Topic: Randomized elements that change upon refresh?  (Read 1002 times)
KatiePla.net
Jr. Member ⚓︎
**
View Profile WWW


Hey you, backup your files! Yes, do it NOW!
⛺︎ My Room
StatusCafe: katieplanet

Artifacts:
Under Construction Gif ProviderJoined 2024!
« on: a Spring night » Embed

Hi everyone!

Y'all may have seen a few previous posts of mine looking for retro ads to add to my website, and thanks to all the awesome contributions y'all have made, I have a great collection of ads I'd love to add to my site.  :ha:

As for their implementation, I'd love for them to be randomized, with a different ad showing on each refresh. I am not sure how to code this, however I'd love to learn! If anyone has any advice or direction on how to code a randomized element, I'd really appreciate it.

Thank you!  :transport:

Logged

     https://katieplanet.neocities.org/ForumPosts/fruit.png

World's #1 Tamanotchi Fan - Please feed DJ★Starr!! (He likes fruit!)

DJ★Starr says..."Backup your favorite files NOW, there is no better time than today! Always support the best option for the world, not the most likely one! Going vegan is really worth considering - modern animal agriculture is terribly cruel. You are so unique and needed in this world - never be afraid to shine your true light! You are always allowed to change, and you're capable of incredible transformation! Trans rights are human rights! Be brave."
P_quod
Newbie ⚓︎
*
View Profile WWW


I can't be sure of anything
⛺︎ My Room

Artifacts:
Joined 2025!
« Reply #1 on: a Spring day » Embed

Hiya!

Well, I don't know if it would be the easiest solution for you if you're not familiar with the language, but I'd use some javascript to do what you describe.

To make it quick, I would:

- Create an array with all my images src
Code
let myArray = ["my-first-image-src", "my-second-image-src", "etc"]
- Create a function that picks a random src in that array and fills my image src with it. Something like that:
Code
function randomImg(){
let randomNumber = Math.floor(Math.random() * myArray.length);
let randomImg = myArray[randomNumber];
document.getElementById("the-id-of-my-img-div").src = randomImg;
}
- Call the function when my page loads
Code
window.onload = randomImg()

I googled "display random image onload javascript" and one of the first entries looks like it would do the job (and maybe it would offer you a better explanation than mine!)

Hope this answer will be helpful  :seal: 

« Last Edit: a Spring day by P_quod » Logged

https://web.archive.org/web/20090901193917/http://geocities.com/nikoanime/whale.gif
xwindows
Full Member
***
View Profile


⛺︎ My Room

Artifacts:
Great Posts PacmanJoined 2024!
« Reply #2 on: a Spring day » Embed

Half a year ago, someone asked for a very similar thing; which I answered with several solutions, both server-side and client-side-- each approach outlined with detailed requirements and tested conditions. You might want to take a look.

Logged
Pages: [1] Print Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi
@000 MelonLand Zap! Want to Login or Join ? Forum Art Hub Chat Webring Editor Recent Edits Tenement Arcade Web Guides Graphics Catalogue Wiki Newsletters Image Stream
Melon's Sites TamaNotchi Textures PixelSea GifyPet MoMG Ozwomp Online Loom Videos Leaky Webring Melonking
Tools Melon Software ArtHub Embed Maker ML Passports
Outlinks Webrings Internet Phone Book HTML Energy Declarations Hackers & Designers Frutiger Aero Forum m15o's Web Services 32Bit Cafe iMood
Minecraft: Online
Join: craft.melonking.net