kalloway: Lit patio lanterns (Patio Lanterns)
[personal profile] kalloway posting in [community profile] smallweb
Hi [community profile] smallweb! Let's chat!

Chatter posts are irregularly-occurring posts to... chat in. Show off what you're working on, what cool stuff you've found lately, what's going well or not so well or anything else. Stop in to say Hi if you want.

Date: 2024-11-28 04:57 pm (UTC)
aleteoryx: A female player avatar sits in a void, in futuristic clothing, conjuring a sphere of trans-colored magic energy. (Default)
From: [personal profile] aleteoryx

"if anyone knows how to use the same "random link" JavaScript multiple times on the same page"

assuming you mean different sets of links for each, you could do something like

<script>
  var sites_a = [
    "/url/of/option/one",
    "/url/of/option/two"
  ];

  var sites_b = [
    "/url/of/different/option/one",
    "/url/of/different/option/two"
  ];

  function randomSite(sites) {
    var i = parseInt(Math.random() * sites.length);
    location.href = sites[i];
  }
</script>

<a href="#" onclick="randomSite(sites_a);">Click me to go to a random site in set A</a><br>
<a href="#" onclick="randomSite(sites_b);">Click me to go to a random site in set B</a>

you can add as many arrays as you want, as long as you pass the right one to randomSite in the onclick handler

Edited Date: 2024-11-28 05:11 pm (UTC)

Profile

smallweb: A drawing of a small spiderweb between branches (Default)
All Things Small Web

March 2026

S M T W T F S
1234567
891011121314
15161718192021
22232425262728
293031    

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Apr. 13th, 2026 01:45 pm
Powered by Dreamwidth Studios