Make external links open in new tabs

This commit is contained in:
Noah 2022-08-26 20:38:17 -07:00
parent 0410065d5d
commit 9c1985e01e
2 changed files with 10 additions and 12 deletions

View File

@ -1,6 +1,16 @@
// Hamburger menu script for mobile. // Hamburger menu script for mobile.
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
// Make all off-site hyperlinks open in a new tab.
(document.querySelectorAll("a") || []).forEach(node => {
let href = node.attributes.href;
if (href === undefined) return;
href = href.textContent;
if (href.indexOf("http:") === 0 || href.indexOf("https:") === 0) {
node.target = "_blank";
}
});
// Hamburger menu script. // Hamburger menu script.
(function() { (function() {
// Get all "navbar-burger" elements // Get all "navbar-burger" elements

View File

@ -145,16 +145,4 @@
</div> </div>
</div> </div>
<script type="text/javascript">
window.addEventListener("DOMContentLoaded", (event) => {
let $file = document.querySelector("#file"),
$fileName = document.querySelector("#fileName");
$file.addEventListener("change", function() {
let file = this.files[0];
$fileName.innerHTML = file.name;
});
});
</script>
{{end}} {{end}}