2

I tried putting a link to an answer in the comments of another answer on the same page using the share link.

That works, but the link that takes you to show the answer involves a page reload.

Is there a way we can put URL fragment links to answers, such as using [#answer2](link to answer)?

Basically, a way which will navigate to the answer which is on the same page without causing the page to reload.

To ease the way of adding links to posts instead copy/paste it should be something like what github does, example if I am writing [internal link](#) as soon as I type # to give the url, it pops out the available answer urls on that page and links them.

Update: We can use #id, where id is the id of the answer, to target them directly but I think it still reloads the page.

Example link to answer below

5
  • 5
    Good request, but it'll take 6-8 weeks.
    – Nissa
    Nov 3, 2017 at 18:55
  • @davidism - I disagree with the duplicate suggestion, as the proposed approach there causes a page reload.
    – Travis J
    Nov 3, 2017 at 19:48
  • 2
    go to answer without reload
    – Oleg
    Nov 3, 2017 at 20:21
  • 1
    Just a test @Oleg, if you came to this comment through notification. try clicking your above link, see if it does reload the page.
    – bhansa
    Nov 3, 2017 at 20:30
  • @bhansa Yep, it broke my solution ;(. Changing the title will also probably break it.
    – Oleg
    Nov 3, 2017 at 20:32

1 Answer 1

5

I think this is a good idea, and it would be ridiculously easy to implement as well.

If you were so inclined, you can create these yourself. Creating URL fragments require a legitimate target to use, and in the case of linking to same page answers luckily the id of the element will work.

The id of the answer element is the same as the value in the share link prefaced by answer-. So, for example if the share link was https://stackoverflow.com/a/47037297/1026459, then the id you are looking for is 47037297. Now, using your example above, creating a link is easy. <a href="#answer-47037297">local link</a> would work.

It is unfortunately impossible to create such a link at present which is where this feature comes into play. Using [local link](#answer-47037297) simply creates the text version of that. If the regex tester for the []() format would also permit the () section to start with a # then users could manually form these links themselves with little issue and create the URL fragment links.

So, the easy part here I think would be to allow a link to be converted into an anchor element when in the format of []() if the parameter for () starts with #.

5
  • good example, and thanks for editing the question.
    – bhansa
    Nov 3, 2017 at 19:20
  • 1
    Thanks, hopefully the question edit reflected your original intent, that was at least what I had interpreted. I think it is a good idea.
    – Travis J
    Nov 3, 2017 at 19:21
  • 2
    It's possible test [test](https://meta.stackoverflow.com/questions/358846/can-we-create-url-fragment-links-to-answers-on-the-same-page#answer-358847) go to question
    – Oleg
    Nov 3, 2017 at 20:16
  • I see, the title seems to be a requirement in the link as far as creating a shortcut. That said, as I navigated to this question again from the url related to your comment link, the test did cause a page reload at first.
    – Travis J
    Nov 3, 2017 at 20:32
  • Yes, it's far from perfect.
    – Oleg
    Nov 3, 2017 at 20:36

Not the answer you're looking for? Browse other questions tagged .