Skip to content

Instantly share code, notes, and snippets.

@ricealexander
Created January 4, 2022 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricealexander/b53ab012a31c655cc14d860da102e9a4 to your computer and use it in GitHub Desktop.
Save ricealexander/b53ab012a31c655cc14d860da102e9a4 to your computer and use it in GitHub Desktop.
Script that injects HTML content after itself. An alternative to document.write
<!-- Grove and other Single-Page Applications do not allow document.write() to be loaded on
pages that have been navigated to. In cases where absolutely necessary, we can use an
approach where content is self-injected. -->
<script id="embed">
var script = document.querySelector('#embed');
script.insertAdjacentHTML('afterend', "Hello World");
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment