-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
57 lines (51 loc) · 1.47 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class Header extends HTMLElement {
connectedCallback() {
this.innerHTML = `
<header>
<nav>
<div class="container">
<div class="nav-wrapper">
<div class="logo">
<h1>My App</h1>
</div>
<ul class="menu">
<li><a href="#home.html">Home</a></li>
<li><a href="#about.html">About</a></li>
<li><a href="#services.html">Services</a></li>
<li><a href="#contact.html">Contact</a></li>
</ul>
</div>
</div>
</nav>
</header>
`;
}
}
class Footer extends HTMLElement {
connectedCallback() {
this.innerHTML = `
<footer>
<div class="container">
<p>Copyright 2020.</p>
</div>
</footer>
`;
}
}
customElements.define("main-header", Header);
customElements.define("main-footer", Footer);
const callContent = () => {
var fragmentId = location.hash.substr(1);
fetch(fragmentId)
.then((res) => {
const data = res.text().then((content) => {
document.getElementById("app").innerHTML = content;
});
})
.catch(() => alert("Error !"));
};
if (!location.hash) {
location.hash = "#home.html";
}
callContent();
window.addEventListener("hashchange", callContent);