javascript - AddThis in AJAX - Stack Overflow

I'm trying to get Addthis to work in a div tag that's being loaded with AJAX I read on their

I'm trying to get Addthis to work in a div tag that's being loaded with AJAX I read on their site I had to render the toolbox with javascript

I'm using the code below but it doesn't seem to be working, any help with the function is appreciated. Thanks.

<div id="toolbox"></div>
<script type="text/javascript">
    addthis.method('#toolbox', [configurationObject], [sharingObject]);
</script>

I'm trying to get Addthis to work in a div tag that's being loaded with AJAX I read on their site I had to render the toolbox with javascript http://support.addthis./customer/portal/articles/381263-addthis-client-api

I'm using the code below but it doesn't seem to be working, any help with the function is appreciated. Thanks.

<div id="toolbox"></div>
<script type="text/javascript">
    addthis.method('#toolbox', [configurationObject], [sharingObject]);
</script>
Share Improve this question edited Sep 27, 2012 at 3:49 Eli 14.8k5 gold badges61 silver badges77 bronze badges asked Jul 9, 2012 at 20:21 AnagioAnagio 3,0759 gold badges46 silver badges81 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

Since I don't know that much about your particular problem, I'd start start by looking into addthis.toolbox('.yourClass');

If you have a typical toolbox like this...

<div id="myToolbox" class="toolbox addthis_toolbox addthis_default_style ">
    <a class="addthis_button_facebook" style="cursor:pointer"></a> 
    <a class="addthis_button_twitter" style="cursor:pointer"></a> 
    <a class="addthis_button_email" style="cursor:pointer"></a>
</div>

Once your ajax content has finished loading into the dom you could do the following...

addthis.toolbox('#myToolbox');

However, watch out for this!

Don't put your like button inside your toolbox because when you call the addthis.toolbox method it will create a duplicate like button iframe for some reason. It must be a bug but it took a couple years off my life. Instead you should put it in its own toolbox containing div and call the method on it as well.

In the case of multiple toolboxes

you should probably use a class instead. See the following code for the final example.

html

 <div class="toolbox">
    <a class="addthis_button_facebook_like" fb:like:layout="button_count" addthis:userid="myCompany"></a> 
 </div>
 <div class="toolbox addthis_toolbox addthis_default_style ">
    <a class="addthis_button_facebook" style="cursor:pointer"></a> 
    <a class="addthis_button_twitter" style="cursor:pointer"></a> 
    <a class="addthis_button_email" style="cursor:pointer"></a>
 </div>

javascript:

//on plete of ajax load
addthis.toolbox('.toolbox');
var addthis_config =
{
ui_hover_direction: -1
, ui_offset_left: offsetLeft
, ui_offset_top: -45
, ui_delay: 300
, ui_click: false

};


var addthis_share =
{
url: 'http://www.example.',
title: 'example title'
}

addthis.method("#Button2", addthis_config, addthis_share);

Visit http://www.addthis./forum/viewtopic.php?f=5&t=14137 this may help you.

method is not a valid function of the addthis object. It's a placeholder in the example for you to use a real method name.

You are never really calling anything as you aren't waiting for the DOM to ready:

<script type="text/javascript"> 
    $().ready(function () {
        addthis.method('#toolbox', [configurationObject], [sharingObject]);
    });
</script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745387057a4625485.html

相关推荐

  • javascript - AddThis in AJAX - Stack Overflow

    I'm trying to get Addthis to work in a div tag that's being loaded with AJAX I read on their

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信