Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anchor link with complete URL #51

Open
Anke opened this issue May 31, 2015 · 5 comments
Open

Anchor link with complete URL #51

Anke opened this issue May 31, 2015 · 5 comments

Comments

@Anke
Copy link

Anke commented May 31, 2015

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

@FlowinBeatz
Copy link

Hi @Anke, did you solve this issue in any way?

@Anke
Copy link
Author

Anke commented Feb 5, 2016

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.

@kingsloi
Copy link

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

@FlowinBeatz
Copy link

Thanks a lot, I will give it a try once I have to use a TOC again!

@Anke
Copy link
Author

Anke commented Jan 26, 2018

Great, I'll try that. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants