问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/17992171/change-the-addthis-attribute-addthisurl-and-send-the-new-url-instead-of-the-l