Last active
January 22, 2021 14:35
-
-
Save GitSquared/674263d4b7b36cd1b0eeb5bdf3160b99 to your computer and use it in GitHub Desktop.
Simple HTML Import with custom element that replaces itself with imported content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
window.customElements.define('get-import', class extends HTMLElement { | |
constructor() { | |
super(); | |
if (this.hasAttribute('url')) | |
window.fetch(this.attributes.url.value) | |
.then(res => res.text()) | |
.then(txt => this.outerHTML = txt); | |
} | |
}); | |
</script> | |
<!-- This element will replace itself with the document specified in url attribute --> | |
<get-import url="folder/page.html"></get-import> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment