4

我希望将一些 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事件甚至不会被触发。

4

1 回答 1

4

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

// only have to change the window.location.href bit
addthis.update('share', 'url', window.location.href); 
addthis.ready(); // This will re-render the box.
于 2013-08-08T13:14:41.667 回答