Created
July 9, 2024 12:52
-
-
Save crftr/996aef47450840d622b1edeca8e64611 to your computer and use it in GitHub Desktop.
Pull in and display extra content on a webpage without having to reload the whole page. It's handy for keeping things updated and flexible by loading bits of HTML from other places on the fly.
This file contains hidden or 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
<div id="landingpageContent"></div> | |
<script> | |
fetch("{{htmlFragmentUrl}}") | |
.then(response => response.text()) | |
.then(html => { | |
const range = document.createRange(); | |
range.selectNode(document.getElementById('landingpageContent')); | |
const documentFragment = range.createContextualFragment(html); | |
document.getElementById('landingpageContent').appendChild(documentFragment); | |
}) | |
.catch(error => { | |
console.error('Error fetching HTML fragment:', error); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment