2

How can I make a button on my website when someone from a mobile device clicks on the button to share the link via Facebook app NOT via browser ?

This code works for Facebook messenger application.

   $('.messenger').click(function(){
      window.open('fb-messenger://share?link=' + encodeURIComponent(link) + '&app_id=' + encodeURIComponent(app_id));
    })

I tried to change the code to the code below but the code below is only opening the Facebook application without insert sharing link

$('.fb-app').click(function(){
  window.open('fb://share?link=' + encodeURIComponent(link) + '&app_id=' + encodeURIComponent(app_id));
})
bobi
  • 169
  • 2
  • 16
  • i believe if you have facebook apps installed it will have default links associated to FB to opens using the app by default, have you tried it? – rickvian Dec 16 '22 at 05:44
  • also there could be chance your link or app id is incorrect, can you provide the final string passed to the window.open? – rickvian Dec 16 '22 at 05:50
  • 1
    try this `fb-share-link://share?link=https://www.example.com"` – DSDmark Dec 18 '22 at 06:47

2 Answers2

2

From the answer here, may still work:

$('.fb-app').click(function(){
  window.open('fb://faceweb/f?href=' + 
    encodeURIComponent('https://m.facebook.com/sharer.php?u=' + 
      encodeURIComponent(link)));
})
Nikolay
  • 10,752
  • 2
  • 23
  • 51
-1

This might work. $('.fb-app').click(function(){ var link = 'https://www.example.com'; // Replace with the link you want to share var app_id = '123456789'; // Replace with your Facebook app ID window.open('fb://share?link=' + encodeURIComponent(link) + '&app_id=' + encodeURIComponent(app_id)); });