Created
October 21, 2016 10:23
-
-
Save marijnh/e476c561a1c6b02ea175fd400e028219 to your computer and use it in GitHub Desktop.
Check a page for dangling links to local anchors
This file contains 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
let links = document.querySelectorAll("a[href]") | |
let base = /^[^#]*/.exec(document.location)[0] + "#" | |
for (let i = 0; i < links.length; i++) { | |
let link = links[i], anchor | |
if (link.href.indexOf(base) == 0 && !document.getElementById(anchor = decodeURIComponent(link.href.slice(base.length)))) | |
console.log("Missing anchor: " + anchor) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment