Search code examples
javascriptfacebookfacebook-social-pluginsfacebook-comments

Facebook Comments box redirects to some weird URL


Ok, I've integrated the comments box into my website, and here's is a page from my test site, where you can see the comments box on the bottom:

http://test.canp.co/programming/5/working-with-xaml

There's no problem with this. I've posted a test comment, and I can see it in my Facebook profile. When I click the link to the page from Facebook, it has appended some IDs to use it within its own system, here's the URL when I click from Facebook:

http://test.canp.co/programming/5/working-with-xaml?fb_comment_id=fbc_10150349734853770_19900263_10150349735753770#f2af0d70b1e6c8

However, when I click this link, it opens the page, scrolls to the bottom to the comment, and when the page loads fully, it redirects me to some random nonsense URL, such as http://test.canp.co/2af0d70b1e6c8. That random part changes every time, and, obviously, I'm getting a 404 error.

What could be causing this? A bug within the Facebook comments box itself, or did I do somwething wrong? What should I be doing? I want the comments box in my site.


Solution

  • found the following in contentpage.js on your site:

    window.onload = function () {
        if (location.hash.length > 2) {
            location.replace("/" + location.hash.substring(2));
            return;
        }
    

    Notice the #f2af0d70b1e6c8 at the end of the URL that facebook hits, and the fact that you get redirected to /2af0d70b1e6c8.....

    Given that you're taking location.hash.substring(2) instead of .substring(1), I assume you're looking for #! or #/ followed by whatever resource the user wants. You should explicitly check for those exact formats instead of any old hash.