使用jQuery编辑动态链接

时间:2014-08-06 10:15:16

标签: jquery facebook dynamic hyperlink

我正在使用插件来显示Facebook Feed。一切都很好,除了包含其他FB用户提及的帖子没有正确链接。这似乎是在Facebook的最后,因为他们不添加父网址,所以提供链接 - 父网址+任何个人资料网址。

我已经尝试使用几种jQuery方法来预先添加主Facebook的URL,但我没有运气,因为插件会动态加载所有内容。

我尝试使用的方法是

$( ".section-text a" ).attr( "href", function() {
   return "http://www.facebook.com" + this.href;
});

以下是我的演示:http://jsfiddle.net/dima7b/r48L8/2/

如果你将鼠标悬停在我提供的演示中,例如“Andreas Varady”,你会看到它链接到jsfiddle父URL和facebook URL。

我已经向插件作者寻求帮助,但他也不知道。将主要Facebook URL添加到动态加载的链接的最佳方法是什么。

谢谢

1 个答案:

答案 0 :(得分:0)

(UNTESTED& UPDATED)

尝试更改此内容(位于文件末尾):

jQuery('.dcsns-facebook .section-text a').each(function(i){
    var txt = jQuery(this).attr('href');
    var href = decodeURIComponent(txt.replace("http://www.facebook.com/l.php?u=", "")).split('&');
    jQuery(this).attr('href',href[0]);
});

到此:

jQuery('.dcsns-facebook .section-text a').each(function(i){
    var txt = jQuery(this).attr('href');
    var href = decodeURIComponent(txt);
    jQuery(this).attr('href',href);
});
相关问题