Skip to content

A tiny js script to include html files in html documents

License

Notifications You must be signed in to change notification settings

jonmircha/include-html

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

include-html.js

A tiny js script to include html files in html documents.

How to use


Simply include the include-html.min.js script in your <head> and add a data-include attribute on any valid HTML element.

include-html will fetch the value of that attribute, and replace the element with the fetched file.

If, include-me.html looked like this:

<h1>Hello, world!</h1>

Then, a document like this:

<head>
  <script src="include-html.min.js"></script>
</head>
<body>
  <div data-include="include-me.html"></div>
</body>

Would end up rendering like this:

<body>
  <h1>Hello, world!</h1>
</body>

Important note


In local environments you must emulate a web server (like live server).

Why ?

The script uses the XMLHttpRequest object so it only works through http requests, if you open your HTML file from your hard drive with the file protocol, the request will mark an error CORS.

About

A tiny js script to include html files in html documents

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published