Entrance Chat Gallery Guilds Search Everyone Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining the forum??
August 08, 2025 - @258.55 (what is this?)
Activity rating: Four Stars Posts & Arts: 54/1k.beats Unread Topics | Unread Replies | My Stuff | Random Topic | Recent Posts Start New Topic  Submit Art
News: It's just life :dog: Super News: Upload a banner! (or else!)

+  MelonLand Forum
|-+  World Wild Web
| |-+  ♺ ∙ Web Crafting Materials
| | |-+  GUIDE: Basic Banners for your site


« previous next »
Pages: [1] Print
Author Topic: GUIDE: Basic Banners for your site  (Read 325 times)
Melooon
Hero Member ⚓︎
*****


So many stars!

⛺︎ My Room
SpaceHey: Friend Me!
StatusCafe: melon
iMood: Melonking
Itch.io: My Games
RSS: RSS

View Profile WWWArt

Emergency feel-good teaa silly heart 4 melon :)Ozwomp wants to know your locationHyperactive DonutGreat Posts PacmanOfficially Dog
« on: July 22, 2025 @46.97 »

:wizard: Basic Banners :wizard:

A BUNCH of people have been asking me if they can copy the code from the melonland eLink banner system to their site . SO I made a very quick edited down version of the code that you can use to host banners on your own site!

This is not intended to be a whole fake ad network (although you could use it for that if you put it in an iframe), its mostly intended for you to make your own pretend banners on your site!

Features:
  • Lets you set a url, image and alt text for each banner
  • Unlimited banners!
  • Have an unlimited number of banners on each page!
  • Auto refreshes banners every few seconds!
  • Limit: this version of the script only works with one size of banner, so pick wisely!

Tip: you can search "banner ad sizes" to get an idea of typical banner sizes, HOWEVER I highly recommend you change them a bit, (use 700x80 instead of 728x90) - this is because many ad-blockers will block typical banner size images. I also suggest you avoid using the word "ad" anywhere in the link or alt text because those get blocked too!

Setup:
1. Include this in your CSS styling, update the size to match the size of your banner images!

Code
.miniBanner img {
    width: 32px;
    height: 32px;
}

2. Next include this JavaScript, either directly on your page in <script> tags OR save it as miniBanner.js and link it on your page:
Code
// Basic Banner Script v0.1 by Melon
// This script lets you create auto changing banners on your site!
// Get help with this script here: https://forum.melonland.net/index.php?topic=4584

let miniBanner = {}; // This is a box for your banner related variables
miniBanner.loop = undefined; // do not edit
miniBanner.count = -1; // do not edit
miniBanner.links = []; // do not edit

// ==== DO Your EDIT here!! ====
// Add your links and images here: miniBanner.links.push({ url: "", image: "", alt: "" });
miniBanner.links.push({ url: "", image: "", alt: "" });
miniBanner.links.push({ url: "", image: "", alt: "" });
// paste as many of these as you like ^^

miniBanner.loopTime = 20; // In seconds - how often does your banner refresh

// ==== No need to edit anything below here unless you wanna experiment! =====
// Startup function to get everything going when the page loads!
window.addEventListener("DOMContentLoaded", (event) => {
    if (miniBanner.elements != undefined)
        return; // The script has already been setup
    miniBanner.elements = document.getElementsByClassName("miniBanner");
    updateBanners(); // First banners
    setInterval(updateBanners, miniBanner.loopTime * 1000); // Banner loop
});

// This is the function that updates the image and link on each banner!
function updateBanners() {
    for (let i = 0; i < miniBanner.elements.length; i++) {
        let miniBannerElement = miniBanner.elements[i];
        
         // Pick the next banner!
        miniBanner.count++;
        if(miniBanner.count > miniBanner.links.length-1) miniBanner.count = 0;
        let newBannerLink = miniBanner.links[miniBanner.count];
        
        // Set up the banner if its the first time!
        if (!miniBannerElement.hasChildNodes()) {
            let link = document.createElement("a");
            link.target = "_blank";
            link.href = "#";
            let img = document.createElement("img");
            img.alt = "Loading...";
            img.src = "#";
            link.appendChild(img);
            miniBannerElement.appendChild(link);
        }
        
        // Update the banner!
        miniBannerElement.firstChild.href = newBannerLink.url;
        miniBannerElement.firstChild.firstChild.alt = newBannerLink.alt;
        miniBannerElement.firstChild.firstChild.src = newBannerLink.image;
    }
}

3. To add your banner links and images, just replace the "miniBanner.links.push" lines with your own images and links, you can add as many push lines as you like! For example:
Code
miniBanner.links.push({ url: "/home.html", image: "/images/totoro.JPG", alt: "My Homepage" });

4. FINALLY: to make banners appear on your page, just add a bunch of elements with the miniBanner class set, this script will replace any element with miniBanner as its class with a mini banner!
For example, you might put of few of these around your site:
Code
<span class="miniBanner"></span>

Good luck making banners!  :ozwomp:
« Last Edit: July 22, 2025 @52.86 by Melooon » Logged


everything lost will be recovered, when you drift into the arms of the undiscovered
NinAcTi0N
Casual Poster ⚓︎
*


Fellow artist, web designer, and local birb :]

⛺︎ My Room
iMood: NinAcTi0N

View Profile WWW

Joined 2024!
« Reply #1 on: July 22, 2025 @706.83 »

Ohh, this is exactly what I was looking for x] Thank you so much for this, Melon!!  :4u:
Logged

Pages: [1] Print 
« previous next »
 

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