angry_kiwi angry_kiwi - 1 year ago 295
jQuery Question

how to simulate the click event on the facebook share button

I want to use jquery/js to simulate the click on original fb share button when I click my custom button.

This is what I've got:

// initialize fb sdk
window.fbAsyncInit = function() {
appId : '830561340319450',
xfbml : true,
version : 'v2.2'

(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); = id;
js.src = "//";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

<div class="fb-share-button" data-href="" data-layout="button"></div>
<button class="my_own">Lets share</button>

I want when I click on my_own, the facebook stock button also get clicked. Any idea how to do that?

Answer Source
  1. Remove the Facebook share button. Trying to trigger a click on it is not the way to go; it might even trigger measures they have in place to prevent click-jacking, and as a result get your app blocked by FB.

  2. Implement the call to the Share dialog when the user clicks your own button:


<button class="my_own" type="button" onclick="share();">Lets share</button>


function share() {
    method: 'share',
    href: '',
  }, function(response){});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download