netfriend's website helpers

HTML Loader

This script uses JavaScript to make snippets of HTML appear on all the pages you paste this script into.


Demo

Directions

Add the following code to the end of your webpage, just above the </body> tag.

Then save the following to a file named html_loader.js, in the same folder as your webpage.

Inside html_loader.js, between const html_templates = { and };, add a new line for every HTML snippet you want to insert.

For example:

will insert the contents of the file /templates/footer.html when it finds the following tag on your webpage, replacing everything inside:

If the template also has a <head> tag, its contents will be added to the page's <head> tag.

Don't forget the comma at the end!