Open Anke opened 9 years ago
Hi @Anke, did you solve this issue in any way?
Uh, thank you for your reply, but honestly - I don't know. I might have, but might just as well have implemented another script. Sorry.
Really hacky solution, but I wanted something simple rather than sinking any time into it. I ended up with:
$('.toc').on('click', 'a', function() {
var fixedUrl = window.location.href.split('#')[0] + $(this).attr('href');
setTimeout(function() {
window.location.replace(fixedUrl);
}, 600);
});
The timer is for the url to update once the smooth scroll has finished + a lil bit of padding. Awkward, but works. @030media @Anke
Thanks a lot, I will give it a try once I have to use a TOC again!
Great, I'll try that. Thanks!
Hi,
thanks for this neat script. Using a CMS I need to add the URL to the anchor name in the link, so I changed line 70 from
.attr('href', '#' + anchorName)
to.attr('href', window.location + '#' + anchorName)
.EDIT: The above change of code seemed to be working well at first, but now I realise that something isn't working well. Clicking on another link now, the anchor is being added to the URL - http://mydomain.com/mypage.html#toc38#toc19. Refreshing the page adds yet another anchor to the URL etc.
Did I trigger this behavior by adding window.location? Is there a solution for this?
I'd very much appreciate your help, Anke