facebookfacebook-likefacebook-sharer

Facebook share link without JavaScript


The following link is for sharing a page on Twitter:

http://twitter.com/share

Is there a similar option for Facebook that doesn't require 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).


Solution

  • You could use

    <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. 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}"

    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();
        }
    }