Search code examples
javascriptphphtmlfacebookfacebook-share

Facebook Sharing button on website


I currently have a facebook sharing button on my website and it works wonderfully for desktops, but from the mobile side of it, it only opens up a new tab in the mobile browser, but I'm looking for it to open the facebook app on the mobile device.

I just have this simple code block doing the current share button.

<div class="fb-share-button" data-href="<?= URL ?>" data-layout="button"></div>

As well as this script at the top.

 <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/sdk.js#xfbml=1&version=v2.3";
   fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

If anyone can point me in the right direction I'd really appreciate it.


Solution

  • There has been some discussion about this already, and after a bit of reading around I'm not sure the situation here has changed much beyond what this answer says.

    The danger with trying to link directly to an app from a website is that links can behave unpredictably if the user doesn't happen to have the app in question installed. I'd personally stick to a web dialogue, and leave the onus on the platform itself (in this case Facebook) to have an 'open in app' button within their mobile page, much like for instance Instagram already does.

    You could start experimenting with fb:// URLs, but of course they would only work for people with the app installed, and that's not something you're going to be able to check with each http request - this answer might also be useful.