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?
3 Answers
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).
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.
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.
http://meta.../126169/comment-links-within-the-same-question
http://meta.../126169/comment-links-within-the-same-question-redirect
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.
-
-
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. Commented Mar 19, 2012 at 22: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.
-
3Anyone using IE 7 should be blocked from SO. Maybe not the entire network, but SO. C'mon people you shoukd know better! Commented Apr 4, 2012 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! Commented Feb 2, 2013 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?– SamBCommented Sep 20, 2016 at 20:53
[status-wontfix]