Last active
November 1, 2019 15:27
-
-
Save kavun/b3bd13bbb7bd5fe190481b047576b89c to your computer and use it in GitHub Desktop.
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
<!-- include this in the <head> --> | |
<base href="https://SITE_DOMAIN.com" /> | |
<!-- include this at the end of the <body> --> | |
<script> | |
!(function () { | |
function forceAbsoluteHashHrefs() { | |
// turn href="#..." into absolute hash links, since with <base> pointed | |
// to a different origin, any relative hash links will cause a browser navigation | |
var baseHref = window.location.href.replace(window.location.hash, ''); | |
[].forEach.call(document.querySelectorAll('[href^="#"]'), function (el) { | |
el.href = baseHref + el.getAttribute('href'); | |
}); | |
} | |
forceAbsoluteHashHrefs(); | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment