简体   繁体   中英

AddThis in AJAX

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.com/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>

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 complete 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.com',
title: 'example title'
}

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

Visit http://www.addthis.com/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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM