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

孤街醉人 提交于 2019-12-24 18:09:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!