Search code examples
htmltwitterfacebook-likelinkedin-api

How to add facebook like button ,linkedin share button and twitter tweet button for each link on a page?


I have gone through many questions already asked about this problem but i didn't really get any clear solution.. I am building a web-site using asp.net and i have several links on a page. I need facebook like button, linkedin share button and twitter tweet button below each link. How can i achieve multiple buttons efficiently without much page load problem.. Also is there a way to know that the user has clicked the button and successfully liked a link...


Solution

  • My two cents

    Facebook button

    In the HTML tag

    <html xmlns:fb="http://ogp.me/ns/fb#">
    

    Right after the body tag

    <div id="fb-root"></div>
    <script>(function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) return;
      js = d.createElement(s); js.id = id;
      js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=<YOUR APP ID HERE!!>";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>
    

    Where your link is

    <fb:like href="<% Response.Write(Server.UrlEncode(linkURL)); %>" send="true" width="450" show_faces="true"></fb:like>
    

    Linked in

    <script src="//platform.linkedin.com/in.js" type="text/javascript"></script>
    <script type="IN/Share" data-url="<% Response.Write(Server.UrlEncode(linkURL)); %>" data-counter="right"></script>
    

    Twitter

    <a href="https://twitter.com/share?url=<% Response.Write(Server.UrlEncode(linkURL)); %>" class="twitter-share-button" data-lang="en">Tweet</a>
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
    

    Essentially you just set the link url to the variable linkURL so that it will print it out to the webpage. I may be wrong, if I am please let me know and I will help you.