html - Create a custom Facebook Share link -


so question has been asked before, no 1 wants in manner want to, bear me while try , explain. fb.ui api has functions find useful, can dynamically change description. so, want put fb.ui link user can click , pop appear can share webpage. far have is:

<div id="fb-root"></div>     <script>  function sharefb(){        window.fbasyncinit = function() {         fb.init({           appid      : '42352352356463',           status     : true,           xfbml      : true         });         fb.ui(   {    method: 'feed',    name: 'name',    caption: 'caption',    description: (         ),    link: 'http://www.image.com/',    picture: 'http://www.image.com/static/3.png'   },   function(response) {     if (response && response.post_id) {       alert('post published.');     } else {       alert('post not published.');     }   } );       };        (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";          fjs.parentnode.insertbefore(js, fjs);        }(document, 'script', 'facebook-jssdk'));  } </script> 

and have link here:

<a class="links" onclick='sharefb()' href="#"> share! </a>   

but doesn't work. why not!

you loading facebook sdk when click button , that's wrong way load it, change script this:

<div id="fb-root"></div> <script> window.fbasyncinit = function() {     fb.init({       appid      : '42352352356463', // app id       status     : true, // check login status       cookie     : true, // enable cookies allow server access session       xfbml      : true  // parse xfbml     }); };   // load sdk asynchronously (function(d){     var js, id = 'facebook-jssdk', ref = d.getelementsbytagname('script')[0];     if (d.getelementbyid(id)) {return;}     js = d.createelement('script'); js.id = id; js.async = true;     js.src = "//connect.facebook.net/pt_pt/all.js";     ref.parentnode.insertbefore(js, ref); }(document));   function sharefb(){     var obj = {         method: 'feed',         name: 'name',         caption: 'caption',         description: 'description',         link: 'http://www.image.com/',         picture: 'http://www.image.com/static/3.png'     };      function share(response){         if (response && response.post_id) {           alert('post published.');         } else {           alert('post not published.');         }     }     fb.ui(obj, share); }; </script> 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -