Search code examples
javascriptfacebookquery-stringfacebook-sharer

Facebook Sharer not giving Title


I have added a facebook button to my company's site so that people can quickly distribute surveys to users via facebook. It is a pretty simple JavaScript:

function SFace()
{
window.open("http://www.facebook.com/sharer/sharer.php?u=[[:SurveyUrl:]]","Facebook","width=700,height=300,toolbar=0,resizable=0");
}

<img src="http://www.snap-surveys.com/test/face.jpg" onClick="SFace()" />

It works fine, but people want a customized title to appear. So, I added &t=Something, however, when you click the link, it still just shows the long URL. I thought maybe it was because I wasn't using encodeURIComponent. So, I added a variable

var SFace="http://www.facebook.com/sharer/sharer.php?u=[[:SurveyUrl:]]&t=something"; document.write(encodeURIComponent(uri));

And then using that in the function. Same thing, shows the URL and not the title. What exactly am I doing wrong? How can I get it to show a custom title in the shared link?


Solution

  • In case anyone wanted to know my solution:

    First needed to get an App ID from Facebook (get the developer's app, create a new app and set the URL as the base/common domain for the site with the button you are adding). Once you have the ID The URL is:

     http://www.facebook.com/dialog/feedredirect_uri=THE_URL&app_id=YOUR_APP_ID&link=THE_URL_YOURE_LINKINGTO&name=TITLE_YOU_WANT_TO_DISPLAY
    

    My recommendation is to write the full URL out like normal and create a variable with document.write(encodeURIComponent); like in my example above. This will add the appropriate spacing characters.

    If the URL matches the URL listed in the App, you can have a share link with a custom title and can therefore use your own button and not the default Like button that facebook provides.