This zone is sleeping right now! ZzzZZzzz

Better not disturb it! ~You go to the petrol station and buy a slushy instead, everything is cool!~

This area will open again in 000.beats!

(Learn about Swatch Time)

Some other zones are awake :^]


Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
Autumn, 20 Oct 2026 - @966.22
Forum Activity: Two Stars Random | Recent Posts | Guild Recents
News: It's the silly things you'll remember :trash: Guild Events: Weekly zine jam 17: Fashion
Super News: ~~MelonLand's Halloween Profile Design Contest 2026~~
+  MelonLand Forum
|-+  Da Web Revival
| |-+  ✁ ∙ Web Crafting
| | |-+  ♺ ∙ Snippets & Materials
| | | |-+  "Landing" page using Javascript without editing the index.html file?


« previous next »
Pages: [1] Print Embed
Author Topic: "Landing" page using Javascript without editing the index.html file?  (Read 733 times)
Valery_04
Casual Poster ⚓︎
*
View Profile WWW


Zero's girlfriend
⛺︎ My Room

Guild Memberships:
Artifacts:
Nightrave (MMXOC, 8 bits)Joined 2026!
« on: Spring, 25 Apr 2026 @837 » Toggle Font Embed

I would like a quick method for make a "Landing" page (A page that shows up with content warnings and important notes before entering the index/home) in Javascript instead of having de harsh of editing the index.html file. Something like the site closer but instead of closing the page a certain day (closed.html), it shows a landing page (landing.html or entrance.html) to click "enter" for entering the index.html page.

It would be a good help for me because I want to try to code Javascript and see how it works.  :pc:

Logged

https://file.garden/aTyH7uSsXSbubAjB/Val_logo-pixel.png
mrparker
Jr. Member ⚓︎
**
View Profile WWW

⛺︎ My Room

Guild Memberships:
Artifacts:
Visited on Melon's 10th Anniversary!lighthouse keeper artemisUserJoined 2026!
« Reply #1 on: Spring, 25 Apr 2026 @869 » Embed

You wouldn't need Javascript at all, unless you want it all on one page!

You would have an index.html, and a home.html or some sort of equivalent. On your index.html, you would just have an a tag be the link to redirect to the home.html page.

If you'd want it all on one page, however, you would use javascript. My website does this, and it works flawlessly.

You would use CSS to define a class, like so:

Code
.hide {
    display: none;
}

the display: none tells the browser to simply not display any element with this class (hide, in this case) applied - it will simply not show it at all!

Your code showing the home page content (contained in a div) by default has the .hide class applied to it, and the landing content by default has no class:

Code
<body>
    <div class="hide" id="content">
         ... home content ....
    </div>

    <div id="landing">
        ... landing content ...
    </div>
</body>

In order to make it so the landing page hides and the content shows, inside the landing div you would have a button of some kind, it can be any element (a button, and image, anything really)

The javascript, in this case, would simply remove the "hide" class from the "content" div, and add the "hide" class to the "landing" div:

Code
<body>
    <div class="hide" id="content">
         ... home content ....
    </div>

    <div id="landing">
        ... landing content ...
        <img src="/assets/some/image.jpg" id="enter" />
    </div>

    <script>
         let contentDiv = document.getElementById("content")
         let landingDiv = document.getElementById("landing")
         document.getElementById("enter").addEventListener("click", function() {
             contentDiv.setAttribute("class", "");
             landingDiv.setAttribute("class", "hide");
         });
    </script>
</body>

Now, this is great and all, but what about if the user visits the home page again? They would be re-prompted to re-enter despite already having done so - every time they visit the home page! We can fix this in two ways, one is to define a client-side cookie, or the other is to use local storage. To keep things simple, we'll use local storage.

In our script tag, we would simply do this instead:

Code
let contentDiv = document.getElementById("content")
let landingDiv = document.getElementById("landing")

let hasEntered = localStorage.getItem("entered")

function enter() {
    contentDiv.setAttribute("class", "");
    landingDiv.setAttribute("class", "hide");

    if (!hasEntered) {
        localStorage.setItem("entered", true)
    }
}

if (hasEntered == true) {
    enter()
}

document.getElementById("enter").addEventListener("click", enter);


Using localStorage is great, since it persists between visits, and also when the browser is closed. You can use cookies, however to keep this example simple, I decided to use localStorage instead.

Keep in mind, the downside to doing this with javascript is that the user can have javascript turned off in their browser. If you are worried about that, you should stick to using just HTML and have a separate page for the home page.


If you want to read more into this, I'd suggest the following resources:
https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
https://developer.mozilla.org/
https://web.dev

There are also books on this topic, some of these books were used in my college courses:
"HTML and CSS: Design and Build Websites" and "JavaScript & jQuery: Interactive Front-End Web Development" - both by Jon Duckett

« Last Edit: Spring, 25 Apr 2026 @875 by mrparker » Logged
Valery_04
Casual Poster ⚓︎
*
View Profile WWW


Zero's girlfriend
⛺︎ My Room

Guild Memberships:
Artifacts:
Nightrave (MMXOC, 8 bits)Joined 2026!
« Reply #2 on: Spring, 19 May 2026 @035 » Toggle Font Embed

I already did it but... The button and stamp marquees are not moving in the content. What should I do next?

Look https://valkyrias-hideout-art.neocities.org

Logged

https://file.garden/aTyH7uSsXSbubAjB/Val_logo-pixel.png
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 Melon
Land
Forum Art Hub Chat Webring Explore Random Recent Tenement Arcade Want to Login or Join ? Web Craft Guide Graphic Catalogue Wiki Help I'm Lost! Link Land Newsletters Image Stream Minecraft: Online
Zap!
Passport Sites tamaNOTchi Asatte Add your site?
Aero Archive Onio Cafe 32 Bit Cafe Status Cafe