Change location hash when clicking a heading link
MODIFY
website/static/js/index.js
website/static/js/index.js
@@ -84,9 +84,13 @@ const toc = {
const target = event.target;
event.preventDefault();
+ const hash = target.getAttribute("href");
+
if(target.hasAttribute("href")){
- scrollToHeading(target.getAttribute('href'));
+ window.location.hash = hash;
+
+ scrollToHeading(hash);
if(isMobile()){
mobileToggleEvent(event);
@@ -103,6 +107,7 @@ function scrollToHeading(hash){
heading.setAttribute('tabindex','-1');
heading.focus();
+
const marginTop = parseFloat(window.getComputedStyle(heading).marginTop, 10);
window.scrollTo(0, (heading.offsetTop) - toc.getMobileNavbarHeight() - (marginTop - 2));
}
@@ -177,7 +182,11 @@ document.addEventListener('click', function (event) {
event.preventDefault();
- scrollToHeading(event.target.getAttribute('href'));
+ const hash = event.target.getAttribute('href');
+
+ window.location.hash = hash;
+
+ scrollToHeading(hash);
}, false);

Change location hash when clicking a heading link