2012-07-24 132 views
0

我想在Facebook分享按钮中提供不同的网址,而不是当前网页网址。facebook分享按钮的不同网址

我试图在asp.net后面更改url,但我没有成功。

如果有人可以帮忙,我会很感激。

我用过的一些代码,你可以看到下面的代码。

这是前侧脚本

<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"> 
</script> 
<script type="text/javascript"> 
function fbs_click() { 
u = location.href; 
t = document.title; 
window.open('http://www.facebook.com/share.php?u=' + encodeURIComponent(u) + 
'&t=' + encodeURIComponent(t), 'share', 'toolbar=0,status=0,width=626,height=436'); 
return false; 
} 
</script> 

这是分享按钮

<a name="fb_share" runat="server" id="aFbShare" type="button" class="sharelink">Paylaş</a> 

这是我做的背后侧

string wishListUrl = SEOHelper.GetWishlistUrl(NopContext.Current.User.CustomerGuid); 
aFbShare.Attributes.Add("onclick", "fbs_click()"); 
aFbShare.Attributes.Add("target", "_blank"); 
aFbShare.HRef = "http://www.facebook.com/share.php?u=" + wishListUrl; 
+1

请提高您的接受率 – 2012-07-24 12:34:30

回答

2

您遇到的问题是这样的。用户点击您的按钮:

<script type="text/javascript"> 
function fbs_click() { 
    u = location.href; 
    t = document.title; 
    window.open('http://www.facebook.com/share.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'share', 'toolbar=0,status=0,width=626,height=436'); 
    return false; 
} 
</script> 

在此功能中,u是当前的URL,t是当前标题。你打开一个Facebook的新窗口,然后返回false。这意味着您的链接从未实际遵循,因为false会告诉浏览器不应再进行点击处理。你应该做的是修改代码隐藏:

string desiredTitle = "My Wishlist"; 
string wishListUrl = SEOHelper.GetWishlistUrl(NopContext.Current.User.CustomerGuid); 
aFbShare.Attributes.Add("onclick", "fbs_click('" + wishListUrl + "', '" + desiredTitle + "')"); 

并修改客户端脚本:

<script type="text/javascript"> 
function fbs_click(url, title) { 
    window.open('http://www.facebook.com/share.php?u=' + encodeURIComponent(url) + '&t=' + encodeURIComponent(title), 'share', 'toolbar=0,status=0,width=626,height=436'); 
    return false; 
} 
</script> 

如果你需要维持目前的冠军,距离的onclick去掉标题变量调用和函数签名,并像以前那样从文档中提取标题。