簡體   English   中英

在addthis共享欄上動態更改URL,但除共享計數外,其他所有功能

[英]Changing the URL dynamically on addthis share bar works on all but the share count

我在頁面上有一個模式,在頁腳中有addthis共享按鈕。 我在頁面上有一個項目列表,當單擊這些項目時,將通過ajax內容填充模態。

我正在做的是在點擊時動態更改addthis:url和addthis:title。

因此,這是簡化到頁腳的模式:

<div class="modal">
  ...
  <div class="modal-footer">
    <div class="addthis_toolbox addthis_default_style">
      <a class="addthis_button_preferred_1"></a>
      <a class="addthis_button_preferred_2"></a>
      <a class="addthis_button_preferred_3"></a>
      <a class="addthis_button_preferred_4"></a>
      <a class="addthis_button_compact"></a>
      <a class="addthis_counter addthis_bubble_style"></a>
    </div>
  </div>
</div>

然后,當單擊一個項目時,我傳入一些變量以更改url和標題:

addthis.toolbox(".addthis_toolbox", null, { title: theTitle, url: theUrl });

問題是<a class="addthis_counter addthis_bubble_style"></a>

這是末尾的計數泡沫:

添加這個例子

url和標題更改就很好,但是計數器永遠不會更改。

我已經提交了一個關於addthis的支持請求,其中缺少一個體面的響應,詢問我是否已調用addthis.init(),當然可以。 共享欄已初始化且正在運行,但計數未更新。

在此處搜索網絡和其他問題,以及關於addthis的文檔,有許多種復雜的方法可以處理基於Ajax的內容。

我的代碼與示例之間的區別在於,ajax內容包括實際的按鈕,而我的則沒有。 我的共享工具欄仍保留在頁面上,僅更改了addthis:url和addthis:title。

也許我錯過了一些小步驟,或者也許這是一個錯誤,而不是我的錯。

希望有人可能有一些見識。

編輯

我終於從addthis得到了回應,並指出這是不可能的。 如果調用工具箱函數,則不會刷新計數。

但是下面評論和答案中顯示的Joseph的變通辦法目前已解決了該問題,至少直到他們提供了更合適的解決方案為止。

經過反復試驗,似乎addthis.counter方法是刷新計數器的方法。 關於該方法的很少文檔似乎僅指的是僅使用沒有任何參數的方法( 我發現了一個論壇帖子 ),這可能會刷新靜態共享元素的計數器(未確認); 但是,當您添加用於addthis.toolbox方法調用的相同屬性時,它將正確刷新計數器。 在調用counter方法時,您必須提供計數器的類,而不是工具箱。 例如addthis.counter('.addthis_counter', null, { url: 'http://example.com'}); 官方文檔可以在這里找到: http : //support.addthis.com/customer/portal/articles/1365325-rendering-tools-with-javascript

這是摘要代碼:

的HTML

<!-- Go to www.addthis.com/dashboard to customize your tools -->
<div class="addthis_toolbox addthis_default_style">
    <a class="addthis_button_preferred_1"></a>
    <a class="addthis_button_preferred_2"></a>
    <a class="addthis_button_preferred_3"></a>
    <a class="addthis_button_preferred_4"></a>
    <a class="addthis_button_compact"></a>
    <a class="addthis_counter addthis_bubble_style"></a>
</div>
<input type="text" value="http://example.com">

的JavaScript

$(function(){
    addthis_config = addthis_config || { };
    addthis_config.pubid = prompt('Provide pubid:');
    addthis.init();

    $('input').on('input',function(){
        $(".addthis_toolbox .addthis_counter").replaceWith('<a class="addthis_counter addthis_bubble_style"></a>');
        addthis.toolbox(".addthis_toolbox", null, { title: 'test', url: this.value });
        addthis.counter('.addthis_counter', null, { url: this.value });
    }).trigger('input');
});

請注意,JavaScript會提示您輸入發布號。 這僅用於演示,您可以將其更改為addthis_config.pubid = 'xx-xxxxxxxxxxxxxxxx'; 為您的應用程序。

演示版

jsfiddle

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM