问题描述
主文件:
. . . . . . .
<div id=“Box-to-fill”></div>
. . . . . . .
<a href="#Box-to-fill” onclick=“execAjax0(N,addThisRefresh);">
. . . . . . .
<!-- Share web page -->
<div class="addthis_toolBox addthis_default_style addthis_20x20_style">
<a class="addthis_button_whatsapp"></a>
<a class="addthis_button_facebook"></a>
</div>
. . . . . .
<script src="https://s7.addthis.com/js/300/addthis_widget.js#pubid=MyId" async="async"></script>
. . . . . . .
<script>
function execAjax0(dinal,callback){
execAjax(dinal); //execAjax(N) calls process_file.PHP?var=N that builds the content of #Box-to-fill
callback();
}
function addThisRefresh(){
addthis.layers.refresh();
}
</script>
process_file.PHP:
<div id=“ATh”>
<!--Share an element with its own url/title/description-->
<div class="addthis_toolBox addthis_default_style"
data-addthis-url=“url”
data-addthis-title=“title”
data-addthis-description=“description”>
<a class="addthis_button_whatsapp"></a>
<a class="addthis_button_twitter"></a>
</div>
</div>
<script>
$(document).ready(function(){
$(“#Ath”).find('[data-addthis-url]').each(function(index){
$(this).attr("addthis:url",$(this).attr("data-addthis-url"));
$(this).removeAttr('data-addthis-url');
$(this).attr("addthis:title",$(this).attr("data-addthis-title"));
$(this).removeAttr('data-addthis-title');
$(this).attr("addthis:description",$(this).attr("data-addthis-description"));
$(this).removeAttr('data-addthis-description');
});
});
</script>
AddThis 按钮在我直接导航 process_file.PHP?var=N 时加载没问题,但当它通过 Ajax 加载时它们不会加载,尽管回调 addthis.layers.refresh() 在 Ajax exec 之后运行。
没有控制台错误。
我尝试了在这里找到的其他答案,但它们似乎已经过时。
编辑 1:
如果我从主页中删除 addThis 源
<script src="https://s7.addthis.com/js/300/addthis_widget.js#pubid=MyId" async="async"></script>
当然不会显示共享按钮,但是如果我将它添加到 ajax process.PHP 文件中(有或没有回调),所有共享按钮都会在 onlick 后显示(页面共享和元素共享)。addthis.layers.refresh();
似乎没有考虑新包含的按钮。
我被困在这一点上。
编辑 2:
用 addToAny 代码替换 process.PHP 中的 addThis 代码:
<div class="a2a_kit a2a_kit_size_20 a2a_default_style" data-a2a-url="element-url">
<a class="a2a_button_whatsapp"></a>
<a class="a2a_button_facebook"></a>
</div>
我得到一个“修复”,直到 addThis 人回答我的问题。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)