Entrance Events! Chat Gallery Search Everyone Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining the forum??
April 19, 2025 - @263.53 (what is this?)
Activity rating: Four Stars Posts & Arts: 86/1k.beats Unread Topics | Unread Replies | My Stuff | Random Topic | Recent Posts Start New Topic  Submit Art
News: ozwomp is requesting your location  :ozwomp: [Agree] Super News: Upload a banner!

+  MelonLand Forum
|-+  World Wild Web
| |-+  ✁ ∙ Web Crafting
| | |-+  Randomized elements that change upon refresh?


« previous next »
Pages: [1] Print
Author Topic: Randomized elements that change upon refresh?  (Read 88 times)
KatiePla.net
Casual Poster ⚓︎
*


Currently: Drinking Seltzer Water

⛺︎ My Room
StatusCafe: katieplanet

View Profile WWW

tamanotchi enthusiast!Under Construction Gif ProviderJoined 2024!
« on: April 06, 2025 @64.62 »

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

    

World's #1 Tamanotchi Fan - Please feed DJ★Starr!! (He likes fruit!)
P_quod
Newbie ⚓︎
*


I can't be sure of anything

⛺︎ My Room

View Profile WWW

Joined 2025!
« Reply #1 on: April 09, 2025 @576.78 »

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: April 09, 2025 @583.46 by P_quod » Logged

xwindows
Casual Poster
*


⛺︎ My Room

View Profile

Great Posts PacmanJoined 2024!
« Reply #2 on: April 13, 2025 @498.68 »

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 
« previous next »
 

Vaguely similar topics! (3)

Case Study - Design elements and hits, should we care?

Started by MelooonBoard ✁ ∙ Web Crafting

Replies: 3
Views: 2328
Last post April 22, 2022 @82.67
by Icey!
Name one small change that would ruin the retro web for you

Started by MemoryBoard ☞ ∙ Life on the Web

Replies: 29
Views: 3394
Last post March 19, 2025 @535.93
by xwindows
Help: how to change which html file appears as my thumbnail on neocities

Started by DJoftheCovenBoard ☔︎ ∙ I need Help!

Replies: 3
Views: 1468
Last post August 15, 2022 @39.04
by DJoftheCoven

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | ~ Send Feedback ~ 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