[英]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 我正在尝试让Addthis在AJAX加载的div标签中工作,我在他们的网站上阅读了这些信息,我不得不使用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'); 由于我不太了解您的特定问题,因此我将从研究addthis.toolbox('。yourClass');开始。
<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... 将您的Ajax内容完成加载到dom后,您可以执行以下操作...
addthis.toolbox('#myToolbox');
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. 不要将“喜欢”按钮放在工具箱中,因为当您调用addthis.toolbox方法时,由于某种原因,它将创建重复的“喜欢”按钮iframe。 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.
相反,您应该将其放在自己的包含div的工具箱中,并在其上调用方法。
you should probably use a class instead. 您可能应该改用一个类。 See the following code for the final example.
有关最终示例,请参见以下代码。
html 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: 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. 访问http://www.addthis.com/forum/viewtopic.php?f=5&t=14137,这可能会对您有所帮助。
method
is not a valid function of the addthis
object. method
不是addthis
对象的有效函数。 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: 您从未真正调用任何东西,因为您不等待DOM准备就绪:
<script type="text/javascript">
$().ready(function () {
addthis.method('#toolbox', [configurationObject], [sharingObject]);
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.