Skip to content

Instantly share code, notes, and snippets.

@cferdinandi
Created November 10, 2022 16:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cferdinandi/c73f0abcf931562041f1f650c15b97a0 to your computer and use it in GitHub Desktop.
Save cferdinandi/c73f0abcf931562041f1f650c15b97a0 to your computer and use it in GitHub Desktop.
<h2>Hi, I'm Chris Ferdinandi.</h2>
<p><strong>I help people learn vanilla JavaScript,</strong> and I believe there’s a simpler, more resilient way to make things for the web.</p>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Includes</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
body {
margin: 0 auto;
max-width: 40em;
width: 88%;
}
</style>
</head>
<body>
<h1>Hate the complexity of modern front-end web development?</h1>
<p>Me too! I send out a short email each weekday on how to build a simpler, more resilient web. Join over 13k others.</p>
<include-html path="about.html">
<a href="about.html">Learn more about me.</a>
</include-html>
<script>
// Extend the HTMLElement class to create the web component
class IncludeHTML extends HTMLElement {
/**
* The class constructor object
*/
constructor () {
// Always call super first in constructor
super();
// Get the source HTML to load
let path = this.getAttribute('path');
if (!path) return;
// Render HTML
this.innerHTML = `<iframe src="${path}" onload="this.before(...(this.contentWindow.document.body||this.contentWindow.document).children);this.remove()">`;
}
}
// Define the new web component
if ('customElements' in window) {
customElements.define('include-html', IncludeHTML);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment