3

我的网站上有这些 AddThis 按钮,我的网站使用 JS 将用户带到图片库,当更改图片时,URL 会使用片段元素中的图片标题进行更新,我遇到的问题是这没有被反映在 AddThis 链接中。我试图从 AddThis 论坛获得一些答案,但被指向 api 文档和 addthis.toolbox() 函数,但它似乎对我不起作用,所以我想我会运行它过去这里的专家。

这是我在基本页面上的 AddThis 代码。

<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style addthis_32x32_style">
<a class="addthis_button_preferred_1 add_this_but"></a>
<a class="addthis_button_preferred_2 add_this_but"></a>
<a class="addthis_button_preferred_3 add_this_but"></a>
<a class="addthis_button_preferred_4 add_this_but"></a>
<a class="addthis_button_compact add_this_but"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript">var addthis_config = {"data_track_clickback":false};</script>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4e77111e2de880eb"></script>

<!-- AddThis Button END -->

在我的 JS 脚本中,当用户更改图像时,我已将其添加到函数中。

addthis.toolbox(".addthis_toolbox");

我也试过这个

addthis.toolbox();

运行代码时,我没有收到任何 JS 错误,但我没有看到 AddThis 按钮的任何更新。

你可以在这里看到问题。

http://www.martynazoltaszek.com/artpages?nid=30#Rendezvouz

此链接将在名为“Rendezvouz”的特定图像上打开站点,但 nid=30 实际上是一个名为“Walking by”的不同图像。AddThis(Facebook)显示问题将始终链接到“Walking by”图像。 AddThis Gmail 似乎没问题,但我不认为这是 API 的一个因素,因为它可以在有或没有上述函数调用的情况下工作。

提前致谢。

ps 使用 ?nid GET 变量和 Fragment 的原因是由于 php 页面加载和 JS 查看(没有页面引用),但这也留下了对非 JS 浏览器的支持。

4

1 回答 1

12

在将 hashbangs 用于 javascript 驱动的站点时,我遇到了类似的问题。使用此代码是因为在异步加载内容时共享按钮不会重新呈现。您应该能够采取其中的一部分以适应您的情况。也许只是addthis.update()代码

首先,我将 addThis 的脚本更改为 async

http://s7.addthis.com/js/250/addthis_widget.js#async=1

加载 DOM 后,监听 hashchanges,这是我们将更新 addthis 共享详细信息的地方。

您可能需要额外的插件才能使用旧版浏览器,请考虑 jQuery hashchange event - v1.3 - 7/21/2010 - http://benalman.com/projects/jquery-hashchange-plugin/

现在它已经为 hashchange 做好了准备,下一步是改变 addThis。

    $(function(){
        $(window).hashchange(function(){
            if($('body').hasClass('addThis')){
                addthis.ost = 0;
                addthis.update('share', 'url', window.location.href); // new url
                addthis.update('share', 'title', window.document.title); // new title.
                addthis.ready(); // this will re-render the buttons.
            }
            else {
                addthis.init();
                $('body').addClass('addThis');
            }
        });
        addthis.init() //As we've changed the addthis to async, you will have to call addthis.init() once the DOM has loaded.
    });

希望这可以帮助。

于 2011-10-10T13:52:31.083 回答