Run
Run

Reputation: 57286

Change the addthis attribute `addthis:url` and send the new URL instead of the loaded URL?

Can I change the addthis attribute addthis:url via jquery/ javascript and send the new url without refreshing the page?

$(".button-addthis").attr("addthis:url", "http://mywebsite/" + location.hash); // example: http://mywebsite.com/#/store/

$(".button-addthis").click(function(){
   alert($(this).attr("addthis:url")); //  example: http://mywebsite.com/#/store/
});

When a page is loaded via ajax, I managed to change the url in addthis:url, but the url that addthis will send is the home page url (which is a loaded url), for example, http://mywebsite.com/ is what addthis sends but not http://mywebsite.com/#/store/

Any ideas?

Upvotes: 1

Views: 3412

Answers (1)

Sol
Sol

Reputation: 1173

Unfortunately, just updating the addthis:url won't update the buttons to share that URL. To update the buttons, you need to call the addthis.toolbox method. Based on your example above, I would suggest:

addthis.toolbox('#addthis_buttons', {}, {'url': 'http://mywebsite/' + location.hash});

This assume you have some element wrapping around your buttons with an id of "addthis_buttons". The second parameter can be left blank and the third parameter is the share object, so you can set url and title if you like. The full documentation on the addthis.toolbox method can be found here:

http://support.addthis.com/customer/portal/articles/1365325-rendering-tools-with-javascript

Upvotes: 5

Related Questions