2012-07-24 97 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去掉標題變量調用和函數簽名,並像以前那樣從文檔中提取標題。