没有JavaScript的Facebook分享链接

没有JavaScript的Facebook分享链接

本文介绍了没有JavaScript的Facebook分享链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下链接用于在Twitter上共享页面:

The following link is for sharing a page on Twitter:

http://twitter.com/share

Facebook是否有不需要JavaScript的类似选项?

Is there a similar option for Facebook that doesn't require JavaScript?

我了解 http://facebook.com/sharer.php ,但这需要了解手动插入的参数(我不打算这样做),或使用JavaScript插入的参数(这不适合我的情况).

I know about http://facebook.com/sharer.php, but that requires a get parameter to be inserted manually (which I'm not going to do), or with JavaScript (which doesn't fit my situation).

推荐答案

您可以使用

<a href="https://www.facebook.com/sharer/sharer.php?u=#url" target="_blank">Share</a>

当前,如果不传递当前网址作为参数,则没有共享选项.您可以使用间接方式来实现这一目标.

Currently there is no sharing option without passing current url as a parameter. You can use an indirect way to achieve this.

  1. 创建服务器端页面,例如:"/sharer.aspx"
  2. 需要共享功能时,请链接此页面.
  3. 在"sharer.aspx"中获取引用URL,并将用户重定向到" https://www.facebook.com/sharer/sharer.php?u= {referer}"
  1. Create a server side page for example: "/sharer.aspx"
  2. Link this page whenever you want the share functionality.
  3. In the "sharer.aspx" get the refering url, and redirect user to "https://www.facebook.com/sharer/sharer.php?u={referer}"

ASP .Net代码示例:

Example ASP .Net code:

public partial class Sharer : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var referer = Request.UrlReferrer.ToString();

        if(string.IsNullOrEmpty(referer))
        {
            // some error logic
            return;
        }

        Response.Clear();
        Response.Redirect("https://www.facebook.com/sharer/sharer.php?u=" + HttpUtility.UrlEncode(referer));
        Response.End();
    }
}

这篇关于没有JavaScript的Facebook分享链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 20:32