user1227914
user1227914

Reputation: 3524

facebook share dialog opening in new tab, not in a popup

I am trying to integrate a Facebook "Share" dialog with the SDK and have the following at the start of the body tag:

<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'MY_APP_ID',
      xfbml      : true,
      version    : 'v2.0'
    });
  };

  (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/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>

Then, as a test link I have:

<a href="https://www.facebook.com/dialog/share?app_id=145634995501895&display=popup&href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2F&redirect_uri=https://developers.facebook.com/tools/explorer
">Test Facebook Link</a>

The problem is that this opens in a new tab, when it should really be opening in a "dialog" window. What am I doing wrong?

Upvotes: 3

Views: 2035

Answers (1)

Elise Chant
Elise Chant

Reputation: 5196

you want:

<div class="fb-like" data-layout="box_count" data-action="like" data-show-faces="true" data-share="true" data-width="59" data-href="https://www.mysite.com/my-awesome-page"></div>

or

<div class="fb-share-button" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button_count"></div>

refer to: https://developers.facebook.com/docs/plugins/share-button/

The Facebook JavaScript basically swaps this out for it's own HTML

Upvotes: 1

Related Questions