更新FB:像URL动态使用JavaScript [英] Update FB:Like URL Dynamically using JavaScript

查看:106
本文介绍了更新FB:像URL动态使用JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用javascript动态更改URL到 FB:Like 按钮。

i'd like to change the URL to like of an FB:Like button dynamically using javascript.

现在我已经只能更改 fb的href属性:像标签(我已经粘贴了下面的代码)。但只是改变href似乎不起作用。也许我必须重新启动FB:像按钮,但到目前为止我无法弄清楚如何..

right now i've only been able to change the href attribute of the fb:like tag (i've pasted the code below). but simply changing the href doesn't seems to work. perhaps i have to re-initiate the FB:Like button, but so far i can't figure out how..

function update_share(container, url) {
  // update fb:like href value
  var container = container[0] || document.body;
  var button = container.getElementsByTagName('fb:like');
  button[0].setAttribute('href', url);
}

任何帮助将不胜感激。 thx ..

any help would be appreciated. thx..

推荐答案

它适用于XFBML标签,而不使用FB iframe,甚至可以与多个FB一样调用AJAX

It works for me for XFBML tag as well without using FB iframe and even works with multiple FB like calls for AJAX

您只需将整个XFBML代码包装在JS / jQuery中,并解析如下:

You just need to wrap the entire XFBML code in JS/jQuery and parse it as shown below:

$('#like').html('<fb:like href="' + url + '" layout="button_count" show_faces="false" width="65" action="like" font="segoe ui" colorscheme="light" />');
if (typeof FB !== 'undefined') {
    FB.XFBML.parse(document.getElementById('like'));
}

HTML代码:

<span id="like"></span>

Surly这将对更多的人有帮助:)

Surly this is going to be helpful for more guys :)

这篇关于更新FB:像URL动态使用JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆