[英]different url for facebook share button
我想在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;
你遇到的問題是這個。 用戶點擊您的按鈕:
<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調用和函數簽名中刪除title變量,然后像以前一樣從文檔中提取標題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.