【问题标题】:Set AddThis URL on the fly when user clicks share用户单击共享时即时设置 AddThis URL
【发布时间】:2013-08-08 13:08:02
【问题描述】:

我希望将一些 URL 参数附加到要由 AddThis 共享的 URL,并且我只会在用户单击共享时知道这些参数。 (我在滑块中显示了一些图像,如果用户单击共享,我想将图像编号附加到 URL,以便 URL 将您带到用户共享的实际图像)。

我尝试使用 AddThis Event API,当有用户要分享的事件时我会收到通知。我当时尝试更改 URL,但它不会更新 URL。 (看来,如果我再次分享,它确实会更改为我之前设置的那个,但这又会过时。

实现这一目标的最佳方法是什么?如果不是通过 AddThis 来实现这一点并支持常见的社交媒体平台(Facebook、Twitter、Pinterest、电子邮件等)的任何更好的东西也可以。

** 更新 **

只是为了澄清我到目前为止尝试过的内容:

   function updateAddThisUrl()
   {
       //slide_no is the variable I am adding as a URL parameter
       var location = window.location;
       var theUrl = location.protocol + '//' + location.host + location.pathname + "?image=" + slide_no;

       addthis_share = {url : theUrl};
       addthis.update('share', 'url', theUrl);
       addthis.url = theUrl; 
       addthis.ready();         
   }

   function eventHandler(evt) 
   { 
       updateAddThisUrl();
   }

   addthis.addEventListener('addthis.menu.share', eventHandler);

上面只更新了后续分享的URL,所以只有当用户再次点击分享时才会生效(此时它又过时了,因为会有一个新的图像,因此会有一个新的URL参数)。我也尝试使用addthis.menu.open,但效果相同,所以我猜它是在此之前使用 URL。我还注意到,如果我从 addthis 弹出菜单中选择电子邮件,addthis.menu.share 事件甚至不会被触发。

【问题讨论】:

    标签: addthis


    【解决方案1】:

    你可以通过调用函数addthis.update来更新你的addthis url:

    // only have to change the window.location.href bit
    addthis.update('share', 'url', window.location.href); 
    addthis.ready(); // This will re-render the box.
    

    【讨论】:

    • 这就是我收到事件时已经在做的事情。当前共享 URL 未更新。
    • 同样,我尝试调用它,添加 og 元标记(即时),将 addthis:url 添加到容器甚至每个共享链接。尝试分享时,我仍然总是得到原始网址。有什么想法吗?
    • 也尝试调用 addthis.toolbox(".addthis_toolbox");如他们的文档中所述(support.addthis.com/customer/portal/articles/…)仍然没有
    • 在您页面上的每个共享工具箱上设置“addthis:url”和“addthis:title”并调用:addthis.toolbox(".addthis_toolbox");不要更改选择器。请参阅我的示例 jsfiddle.net/bs7g9rm8
    猜你喜欢
    • 1970-01-01
    • 2021-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多