Skip to content

Instantly share code, notes, and snippets.

@kavun
Last active November 1, 2019 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kavun/b3bd13bbb7bd5fe190481b047576b89c to your computer and use it in GitHub Desktop.
Save kavun/b3bd13bbb7bd5fe190481b047576b89c to your computer and use it in GitHub Desktop.
<!-- 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