2013-04-09 60 views
4

如何使用addthis社交插件分享url +參數?
我已經閱讀了addthis api,但是我找不到乳清添加我的參數。
http://support.addthis.com/customer/portal/articles/381263-addthis-client-api如何使用addthis社交插件分享url +參數?

<!DOCTYPE HTML> 
<html lang="en-US"> 
<head> 
    <meta charset="UTF-8"> 
    <title>hello world</title> 
</head> 
<body> 
    <!-- AddThis Button BEGIN --> 
    <div class="addthis_toolbox addthis_default_style "> 
    <a class="addthis_button_preferred_1"></a> 
    <a class="addthis_button_compact"></a> 
    <a class="addthis_counter addthis_bubble_style"></a> 
    </div> 
    <script type="text/javascript"> 
    var addthis_config = { 
     // I want to share link as this url + my_defined_paramater, how to set? 
     url: location.href+'refer_id=1900' //not correct 
    }; 
    </script> 
    <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#username=addthis"></script> 
    <!-- AddThis Button END --> 
</body> 
</html> 

enter image description here

+0

你不會碰巧被使用jQuery過你會嗎? – SomeShinyObject 2013-04-09 05:12:33

回答

2

看起來你可能需要在您的網址的符號。 API文檔顯示的其他內容看起來都很好。

var addthis_config = { 
    // I want to share link as this url + my_defined_paramater, how to set? 
    url: location.href+'&refer_id=1900' 
        //^^^ 
}; 

我在支持部分找到了一些項目。希望這會有所幫助。

Support page

基本上,它說,你可以添加屬性稱爲addthis:url設置自定義URL。由於您需要當前頁面,因此您必須使用JavaScript的setAttribute()方法更新它。

<div class="addthis_toolbox addthis_default_style" id="addthis_container"> 
    <a class="addthis_button_preferred_1"></a> 
    <a class="addthis_button_compact"></a> 
    <a class="addthis_counter addthis_bubble_style"></a> 
</div> 
<script type="text/javascript"> 
    var addThisCont = document.getElementById("addthis_container"); 
    var curUrl = location.protocol + "//" + location.href; 
    var withGetVariable = curUrl + "?refer_id=1900"; 
    addThisCont.setAttribute("addthis:url", withGetVariable); 
</script> 
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#username=addthis"></script> 
+0

不,甚至添加&,共享網址發送到Facebook仍然沒有我的參數 – linjuming 2013-04-09 04:50:22

+0

@linjuming,我添加了一些東西,希望這將有助於 – SomeShinyObject 2013-04-09 05:24:50

+0

非常感謝,很好的答案 – linjuming 2013-04-09 06:40:55

0

你應該使用下面的代碼:

addthis_share = { 
    url_transforms : { 
     add: { 
      oReferrer: LoggedOfficeGuid 
       } 
     } 
    } 
+3

Give對你的代碼的一點點解釋。它使你的答案有用。 – 2014-04-10 09:40:40