【问题标题】:Changing the href on gplus & facebook buttons using javascript使用 javascript 更改 gplus 和 facebook 按钮上的 href
【发布时间】:2011-08-18 13:22:47
【问题描述】:

我的网站是[链接删除],当您从主菜单更改页面时,它使用 ajax 加载主要内容 div,这意味着右侧的社交按钮仍指向您登陆的原始页面,如何将它们与页面内容一起更新?

我试过了

$('.sidebar g\\:like').attr("href", x);
$('.sidebar fb\\:like').attr("href", x);

但似乎不起作用

有什么想法吗?我很惊讶我找不到有类似问题的人......

【问题讨论】:

    标签: jquery facebook href google-plus-one


    【解决方案1】:

    这两个按钮都是 iFrame,因此除非您使用 facebook JS API for facebook,否则您将无法做到这一点。我认为 g+ 没有非 iframe 解决方案..

    您需要将整个按钮替换为:

    $('#social').html('<iframes to facebook and g+ buttons />');
    

    【讨论】:

      【解决方案2】:

      转储比 iframe 更容易,然后为类似 facebook 的部分重新添加它:

      $('#social fb').remove(); //fb seems to create a fb:like element... wierd
      
      $('#social').append(
          '<iframe src="http://www.facebook.com/plugins/like.php?href="' + url + '"
          scrolling="no" frameborder="0" 
          style="border:none; width:450px; height:80px"></iframe>');
      

      对 G+ 做同样的事情

      $('#social [id*=plusone]').remove();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-05-23
        • 2016-07-05
        • 1970-01-01
        • 2017-05-10
        • 2014-12-21
        • 2017-07-15
        • 2016-06-22
        • 1970-01-01
        相关资源
        最近更新 更多