更改addthis属性`addthis:url`并发送新的URL而不是已加载的URL? [英] Change the addthis attribute `addthis:url` and send the new URL instead of the loaded URL?

查看:106
本文介绍了更改addthis属性`addthis:url`并发送新的URL而不是已加载的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过jquery/javascript更改addthis属性addthis:url并发送新的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/
});

通过ajax加载页面时,我设法更改了addthis:url中的url,但是addthis将发送的url是主页url(即已加载的url),例如,

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/

有什么想法吗?

推荐答案

不幸的是,仅更新addthis:url不会更新共享该URL的按钮.要更新按钮,您需要调用addthis.toolbox方法.根据上面的示例,我建议:

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});

假设您的按钮周围有一些元素,其ID为"addthis_buttons".第二个参数可以保留为空白,第三个参数是共享对象,因此您可以根据需要设置url和title.可以在以下位置找到有关addthis.toolbox方法的完整文档:

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

这篇关于更改addthis属性`addthis:url`并发送新的URL而不是已加载的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆