jquery - 更改 addthis 属性 `addthis:url` 并发送新的 URL 而不是加载的 URL?

标签 jquery addthis jquery-1.9

我可以通过 jquery/javascript 更改 addthis 属性 addthis:url 并在不刷新页面的情况下发送新的 url 吗?

$(".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),对于例如,http://mywebsite.com/是 addthis 发送的内容,但不是 http://mywebsite.com/#/store/

有什么想法吗?

最佳答案

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

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

假设您有一些元素围绕着按钮,其 id 为“addthis_buttons”。第二个参数可以留空,第三个参数是共享对象,因此您可以根据需要设置 url 和 title。有关 addthis.toolbox 方法的完整文档可以在这里找到:

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

关于jquery - 更改 addthis 属性 `addthis:url` 并发送新的 URL 而不是加载的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17992171/

相关文章:

javascript - 如何使用 tinymce 的复选框按钮在运行时打开和关闭只读模式?

javascript - jquery .html 显示 html 标签,而不是在文本上应用 html 标签

javascript - 从 1.8.3 到 1.9.1 的 jQuery 迁移在一行中停止工作,我不知道为什么

wordpress - 使用 ADDTHIS 分享我的 Google+ 信息页上的内容

php - 使用 ajax 调用时,MySQL 查询数组不会被填充

javascript - 为 Openseadragon 添加注解

javascript - 搜索时如何添加透明背景?

javascript - 通过异步插件加载 addthis

css - AddThis 按钮 CSS 问题

jquery - 每次 Ajax 调用后重新绘制 Google 图表