0

我想在 Facebook 分享按钮中提供一个不同的 url,而不是当前页面的 url。

我试图在后面更改 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;
4

1 回答 1

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>

If you need to maintain your current title, just remove the title variable from the onclick call, and the function signature, and pull the title from the document as you were doing before.

于 2012-07-24T13:04:14.443 回答