Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
Winter, 02 Dec 2026 - @88.24
Forum Activity: Four Stars Random | Recent Posts | Guild Recents
News: Love is not possession  :4u: Guild Events: Melon Jam 2026
Super News: ++ MelonJam 2026 ~ 1st Dec to 1st Jan! ++
+  MelonLand Forum
|-+  Da Web Revival
| |-+  ✁ ∙ Web Crafting
| | |-+  ♺ ∙ Snippets & Materials
| | | |-+  Age Gate for Static Website (Neocities) ?


« previous next »
Pages: [1] Print Embed
Author Topic: Age Gate for Static Website (Neocities) ?  (Read 1462 times)
beebz
Jr. Member ⚓︎
**
View ProfileArt


Profic Plural
⛺︎ My Room

Guild Memberships:
Artifacts:
Trans Thigh HighsxDXD SquishStriped Thigh-High Socksstriped long sleevelil custard
« on: Autumn, 15 Sep 2026 @804 » Toggle Font Embed

Hello, I'm looking for a way to implement an age gate/warnings and consent page on my neocities. Something as boilerplate or bare bones as possible.

Ideally a visit to any page on my site would first pop up the warning with a (click to continue) prompt and as a bonus, an option for the user to check remember me and save something to localstorage so they wont be prompted again.

I've searched before but am inundated with third party and plugin references, I want to keep things simple and within as much of my control as possible.

Thanks for reading! Hope you can help

Logged
Dan Q
Hero Member ⚓︎
*****
View Profile WWWArt


I have no idea what I am doing
⛺︎ My Room
RSS: RSS

Guild Memberships:
Artifacts:
The Worm is creeping around Melonland profiles!Caught by RubbereonThe Worm is creeping around Melonland profiles!Dan Q Cruisin'I DIDN'T meet Dan Q on Melonland!Visited on Melon's 10th Anniversary!
« Reply #1 on: Autumn, 15 Sep 2026 @812 » Toggle Font Embed

Doing it with localStorage/JS means that if the user doesn't have JS enabled, it won't work. I've assumed that in this case, you'd prefer that they're shown the full content (fail-friendly, rather than fail-unusable).

Basic version

Assuming you have a landing page index.html, I'd have some code like this:


Code
<!-- using a plain-old-link means that it'll work if JS is disabled; we'll add some JS later to "enhance" it: -->
<a href="home.html" class="age-gate">Enter the site</a>

<!-- add some JS to capture clicks on the age gate and set localStorage: -->
<script>
document.querySelector('.age-gate').addEventListener('click', function(e){
  localStorage.setItem('age-gate-passed', 'true');
}, { passive: true });
</script>

Then you just need to add something like this to every other page:

Code
<!-- add JS to check if they've seen the age gate and redirect if not: -->
<script>
if(!localStorage.getItem('age-gate-passed')) window.location.href = '/index.html';
</script>

That's an ultra-minimal version of what you're looking for, I reckon! I've not tested it, mind!

Logged

https://danq.me/_q26t/badges/dan-q-88x31-lighter.gif https://danq.me/_q26t/badges/dan-q-88x31-peekaboo-scroller.gif https://beige-buttons.danq.dev/beige-buttons-88x31.gif https://embed-html.danq.dev/embed-html-88x31.gif https://origami.danq.dev/88x31.gif https://skelly.monster/dem-bones-88x31.gif

Artifact Swap: Pink ham-ham rangerPolyamorousI met Dan Q on Melonland!shoeJoined 2025!cinnamoroll3 coins
Dan Q
Hero Member ⚓︎
*****
View Profile WWWArt


I have no idea what I am doing
⛺︎ My Room
RSS: RSS

Guild Memberships:
Artifacts:
The Worm is creeping around Melonland profiles!Caught by RubbereonThe Worm is creeping around Melonland profiles!Dan Q Cruisin'I DIDN'T meet Dan Q on Melonland!Visited on Melon's 10th Anniversary!
« Reply #2 on: Autumn, 15 Sep 2026 @817 » Toggle Font Embed

Advanced version

What would be better would be if, after being redirected to the age-gate, acceptance sends you back to the page you were originally trying to see, in the first place.

So let's expand our "on every page" script:


Code
<!-- add JS to check if they've seen the age gate and redirect if not: -->
<script>
if(!localStorage.getItem('age-gate-passed')) {
  window.location.href = '/index.html?redirectedToAgeGate';
}
</script>

Now we can expand our index.html's JS so that, if '?redirectedToAgeGate' is in the URL, we redirect back on click. That'd make the index.html's JS look like this (note that it's no longer a passive event listener because it can preventDefault()!):

Code
<!-- add some JS to capture clicks on the age gate, setting localStorage and redirecting if necessary: -->
<script>
document.querySelector('.age-gate').addEventListener('click', function(e){
  // Set localStorage to say we've passed the age gate
  localStorage.setItem('age-gate-passed', 'true');

  if(window.location.search == '?redirectedToAgeGate' && window.history.length > 1) {
    // We got here by redirection and we have some history, so go BACK to the page we originally wanted
    window.history.back();
    // and prevent following the regular link
    e.preventDefault();
  }

  // otherwise, carry on as normal (i.e. follow the link!)
});
</script>

Again I've not tested this, but it should be "close enough" to get you started!

Logged

https://danq.me/_q26t/badges/dan-q-88x31-lighter.gif https://danq.me/_q26t/badges/dan-q-88x31-peekaboo-scroller.gif https://beige-buttons.danq.dev/beige-buttons-88x31.gif https://embed-html.danq.dev/embed-html-88x31.gif https://origami.danq.dev/88x31.gif https://skelly.monster/dem-bones-88x31.gif

Artifact Swap: Pink ham-ham rangerPolyamorousI met Dan Q on Melonland!shoeJoined 2025!cinnamoroll3 coins
beebz
Jr. Member ⚓︎
**
View ProfileArt


Profic Plural
⛺︎ My Room

Guild Memberships:
Artifacts:
Trans Thigh HighsxDXD SquishStriped Thigh-High Socksstriped long sleevelil custard
« Reply #3 on: Autumn, 15 Sep 2026 @824 » Toggle Font Embed

Thank you so much! I will test this the next time i do a run at my website and definitely come back to talk about how it went. I thankfully use Astro to build my site so the script on every other page shouldn't be difficult, I could probably put it in the footer component.

Much appreciated

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

Melonking.Net © Always and ever was! SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ Guide | Rules | Whos a Mod? | 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