0

I have a problem with Facebook and Twitter share buttons in my single page web application. My app has 3 views. A,B and C. Facebook and Twitter buttons are on A view. First time that app is loaded and view A is shown is OK I can see buttons and it works. When I move to view B I detach view A (I have to do that) and attach view B and by clicking on back button from View B we go to view A but this time the Facebook and Twitter buttons are now showing.

SharedButton.js

(function() {
define(['jquery'], function($) {

    return {

        init: function(){
            var url = window.location.href;
            $('.fb-share-button').attr('data-href', url);
            (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.5";
                fjs.parentNode.insertBefore(js, fjs);
            }(document, 'script', 'facebook-jssdk'));

            !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');


        }

    };

});
 }).call(this);

Every time I attach view A, shareButton.init() is being called.

Any idea what's the issue and how can I get it working?

Thanks.

Negin Basiri
  • 1,305
  • 2
  • 26
  • 47
  • Detaching the view most likely means that DOM content is removed, and added again later on – so you need to tell the JS SDK to look through that “new” content again to parse the social plugins. See the duplicate for how to do that. – CBroe Feb 18 '16 at 09:43
  • Thanks for directing me to the answer. It solved my problem too. Cheers – Negin Basiri Feb 18 '16 at 22:52

0 Answers0