on 2016-04-20

JavaScript - facebook save to facebook button

2016 F8

Facebook release new function - save to facebook

Then we can use it now

Step 1

Go to facebook developer Save Button - Social Plugins - Documentation - Facebook for Developers

Step 2

Build or use facebook application

If you had facebook application can skip this step

If you build facebook application and you can get this code

window.fbAsyncInit = function() {
    appId      : '<YOUR APP ID>',
    xfbml      : true,
    version    : 'v2.6'

(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'));

Put it in your website

Step 3(Finally

Add <div class="fb-save" data-uri="http://www.your-domain.com/your-page.html"></div>

data-uri is your current page url

You can use this js code dynamic add url

document.querySelectorAll('.fb-save')[0].setAttribute('data-uri', document.location.href);


螢幕快照 2016-04-20 上午11.15.59.png

螢幕快照 2016-04-20 上午11.16.09.png

Then it can show on facebook saved

螢幕快照 2016-04-20 上午11.16.17.png