Reputation: 3277
I'm currently trying to make my facebook share button dynamic. What I'm currently doing is replacing the data-href in the div(I'm using html 5 code)
Apparently I have a list of urls loaded in my javascript. Whenever I click on a button, it replaces the link in my data-href, but when I click the share button, it still uses the preloaded link that was first loaded onto it. How do I change the share button link without having to reload the page all over again?
I replace the data-href using this code:
$(".fb-like").attr('data-href',youtube_str+link);
Upvotes: 0
Views: 929
Reputation: 22852
Bad news, that's not possible using html5 code, good news you can solve that using XFBML.
Just change your <html>
tag to <html xmlns:fb="http://ogp.me/ns/fb#">
so it works on older IE versions
And change your share buttons to this:
<fb:share-button href="http://developers.facebook.com/docs/plugins/" type="button_count"></fb:share-button>
Note: You may have to change the type for the one you want.
Then everytime you change the url and I'm assuming you're using the Javascript SDK, just do this:
FB.XFBML.parse();
It will parse every XFBML on your page, if you don't want to parse every tag, you can use a DOM selector:
FB.XFBML.parse(document.getElementById('foo'));
More info here Facebook Docs and here Facebook Dev wiki
Upvotes: 2