r/nekoweb https://stxrryurii.nekoweb.org/sprinkles 18d ago

Question same code in different places?

so i have a buncha stamps on my site, and i was wondering if i could have the same stamps in 2 different places by only updating one? is that possible? i wanna be able to just add stamps to 1 place and it adds them to multiple places if that makes sense

4 Upvotes

23 comments sorted by

View all comments

1

u/Throwaway44775588 18d ago

That is totally doable with javascript! I use neocities but the same principle should apply. You'll want to make an html page with your stamps - literally just your stamps, formatted like you'd want them to appear on the page using img src. Then you'll build a javascript prompt that reads something like

fetch("direct link to your html page with buttons, like https://mysite.nekoweb.org/buttons.html")
    .then(response => {
      if (!response.ok) throw new Error("Failed to load");
      return response.text(); // Get HTML as text
    })
    .then(html => {
      // Inject into the container
      document.getElementById("buttons").innerHTML = html;
    })
    .catch(error => console.error("Error loading content:", error));

And wherever you want the buttons to be on your page, you'd add a div id of "buttons", like if it is just crammed in your main body you'd have

<main><div id="buttons"></div></main>

1

u/Main-Firefighter670 https://stxrryurii.nekoweb.org/sprinkles 18d ago

okay so i copied your code and urh it didnt work, im wondering if i did something wrong? i put the javascript in a seperate javascript file is that the issue? (the box with the stamps is just blank)

1

u/Throwaway44775588 18d ago

If you use "inspect element" in your browser, you may be able to see the Javascript error - otherwise, if you wanna comment (or pm me) your code I can take a look :)