在twitter引导模式上分享这个

sharethis on twitter bootstrap modal

本文关键字:分享 模式 twitter      更新时间:2024-03-13

我想在twitter引导模式上显示共享这个小部件,但是代码说要执行以下操作:

<span class='st_facebook_hcount' displayText='Facebook'></span>
<span  class='st_twitter_hcount' displayText='Tweet'></span>
<span class='st_plusone_hcount' displayText='Google +1'></span>
<span  class='st_email_hcount' displayText='Email'></span>

所以我所做的是,在bootstrap的shown.bs.mode事件中,我有:

var switchTo5x=true;
    $.getScript("http://w.sharethis.com/button/buttons.js", function(){
        stLight.options({publisher: "c68c8f6c-c670-419b-b8e2-23772e22a861", doNotHash: false, doNotCopy: false, hashAddressBar: false, popup: 'true'});
    });

然而,下次我打开另一个模式时,这个共享按钮不会加载。我想是因为getScript已经存在了吧?

打开新模式后尝试此操作:

stButtons.locateElements();

它将查找新按钮并实例化它们。

编辑:收听show.bs.modal事件进行处理:

$('#myModal').on('show.bs.modal', function () {
  stButtons.locateElements();
})

第2版:好的,在阅读了你的评论后,我认为最终的解决方案是:

var switchTo5x=true;
    $.getScript("http://w.sharethis.com/button/buttons.js", function(){
        stLight.options({publisher: "c68c8f6c-c670-419b-b8e2-23772e22a861", doNotHash: false, doNotCopy: false, hashAddressBar: false, popup: 'true'});
        stButtons.locateElements();
    });