When I link to a comment within the same question, the link doesn't bring me to the comment itself unless I open it in a new tab/window. Can we fix that?

| improve this question | | | | |
  • 1
    Here is a comment. – Double AA Mar 19 '12 at 20:30
  • 4
    Here is a link to that comment. – Double AA Mar 19 '12 at 20:31
  • Try clicking the link, and also try opening it in a new tab/window. – Double AA Mar 19 '12 at 20:31
  • I had the same with Chrome 17.0.963.79. But I guess it is status-bydesign – om-nom-nom Mar 19 '12 at 20:33
  • 2
    @om-nom-nom status-by-design doesn't mean we can't fix it! – Double AA Mar 19 '12 at 20:35
  • 5
    This is strange, meta.judaism.stackexchange.com/questions/950/… works for me – Shmuel Brin Mar 19 '12 at 20:39
  • 3
    @ShmuelBrill The comment link there has an outdated slug, so it gets redirected. If I do the same here, you'll get a working link. – a cat Mar 19 '12 at 21:49
  • 1
    @lunboks I can't quite follow that, but you're saying that the issue is only for the first few minutes/hours that the link exists? – Double AA Mar 19 '12 at 21:55
  • 2
    @DoubleAA No. The question title is embedded in question URLs. If the question title embedded in comment link URLs matches the actual question title, then the browser sees it as the same page with a different anchor, so the link isn't followed. If they don't match (question was edited afterwards, or someone intentionally modified the comment link, like I did), it looks like a different page to the browser, so it follows the link. – a cat Mar 19 '12 at 22:01
  • 1
    @lunboks, aren't anchors routinely used for navigation within a page (with the same base URL), e.g. the sidebar links in the FAQ? – Isaac Moses Mar 19 '12 at 22:04
  • 1
    Eight months later and I'm still experiencing this issue (Chrome 23/FF 16/IE10). It looks like it's [status-wontfix] – NullUserException อ_อ Nov 20 '12 at 22:07
  • Double AA - One of these guys should surely get their answer accepted, no? – user66001 Feb 2 '13 at 18:55
  • @user66001 I've upvoted them, but I was thinking that by accepting an answer the devs would stop looking at this, and I was kinda hoping that the problem would be fixed. – Double AA Feb 2 '13 at 23:21
  • Double AA - Very good thinking! :) – user66001 Feb 3 '13 at 0:02
  • 1
    This just occurred to me: can we make the link in the time-stamp go to /posts/comments/12345 instead of the current long version with #comment12345_54321 – Double AA May 8 '13 at 16:38

This will be fixed in the next build, rev > 2013.5.14.1013.

I took Tim Stone's advice and used the hashchange event - it really cleaned the code up (thanks, Tim).

| improve this answer | | | | |
  • Awesome, thanks Jarrod! :) – Rachel May 15 '13 at 18:04

The problem here is that the site uses pure JavaScript to pop the user down to the appropriate comment, highlight it, and fade the highlight away. The link uses the comment #comment341467_126169, but there is no element on the page with that ID. So when you click it, the browser appends the comment to the URL and searches for it, sees it doesn't exist, and does nothing.

Comment link vs HTML structure

As for the redirection issue mentioned (I think, I kind of skimmed the comments): When you embed a URL to a comment as a link inside another comment or post, that URL becomes hard-coded (it doesn't automatically change to correct the URL). So, if you start with the title Comment links within the same question, but change the title to something like Comment links within the same question redirect after someone posted a link to a comment in that question, the entire URL changes.


Since the URLs do not match before the #comment part, the browser sees the two as entirely different URLs, so it will reload the page.

| improve this answer | | | | |
  • So it's a browser issue, not a SE issue? – Double AA Mar 19 '12 at 22:35
  • 4
    @DoubleAA: No, it's definitely an SE issue. They're linking to an ID in the page that doesn't actually exist, and compensating for it with JavaScript, which is only useful if you hence reload the page. The second issue below the horizontal rule should only occur if the title of the question gets changed. – animuson Mar 19 '12 at 22:38
  • It's almost been an entire year. I realise that this is probably low on the priorities, and we don't manage the dev. teams schedule, but while I haven't gone through the code, seems the below user ¿has provided? the fix, no? – user66001 Feb 2 '13 at 18:38

animuson is right, there's nothing to properly handle the hash change in the current JavaScript, which would be necessary for this to work given the way it's implemented.

With that in mind, throwing

$(window).on('hashchange', j);

into StackExchange.questions.init() would solve the problem (Except in IE7 and other ancient browsers, but meh). It would also allow the

onclick="StackExchange.question.highlightComment(<cid>, <pid>)"

to be removed from the current comment link HTML, since it makes me sad-face.

There's also a larger problem of getting a comment link from an answer if you accessed the answer by a direct URL, since if the question slug changes in the interim you get redirected to the new answer URL, instead of the comment.

That becomes even more problematic if I were to instead get a comment link from the question in such a case, since you don't end up at the right post (you should end up on this comment). A similar scenario could probably come about on questions with more than one page of answers, as well, although that's pretty edge-case.

Making the comment link URLs fully qualified would alleviate some of those issues, though it might cause unnecessary redirects as a result. This happens anyway when you link to answers within the same post currently, so perhaps that's not a huge issue.

Keep in mind that comment linking works only on a "best-effort" basis, so it's understandable if this isn't something worth addressing.

| improve this answer | | | | |
  • 3
    Anyone using IE 7 should be blocked from SO. Maybe not the entire network, but SO. C'mon people you shoukd know better! – Manishearth Apr 4 '12 at 2:58
  • Thanks for the investigation Tim Stone. Not sure why I didn't find this in my research before posting a new question. I don't quite follow with the question slug changing, but think I understand the general concept. What do you mean comment linking is "best-effort" - This is SO! – user66001 Feb 2 '13 at 18:41
  • Re: pagination issues, I wonder why they don't advertise the form <meta.stackexchange.com/posts/comments/485315> better, or the <meta.stackexchange.com/questions/126169/…> that it redirects to: those shouldn't have any problems, right? – SamB Sep 20 '16 at 20:53

You must log in to answer this question.

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