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 1:
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.
- Create a server side page for example: "/sharer.aspx"
- Link this page whenever you want the share functionality.
- 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();
}
}
Solution 2:
Ps 2: As pointed out by Justin, check out Facebook's new Share Dialog. Will leave the answer as is for posterity. This answer is obsolete
Short answer, yes there's a similar option for Facebook, that doesn't require javascript (well, there's some minimal inline JS that is not compulsory, see note).
Ps: The onclick
part only helps you customise the popup a little bit but is not required for the code to work ... it will work just fine without it.
<a href="https://www.facebook.com/sharer/sharer.php?u=URLENCODED_URL&t=TITLE"
onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;"
target="_blank" title="Share on Facebook">
</a>
<a href="https://twitter.com/share?url=URLENCODED_URL&via=TWITTER_HANDLE&text=TEXT"
onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;"
target="_blank" title="Share on Twitter">
</a>
Solution 3:
It is possible to include JavaScript in your code and still support non-JavaScript users.
If a user clicks any of the following links without JavaScript enabled, it will simply open a new tab:
<!-- Remember to change URL_HERE, TITLE_HERE and TWITTER_HANDLE_HERE -->
<a href="http://www.facebook.com/sharer/sharer.php?u=URL_HERE&t=TITLE_HERE" target="_blank" class="share-popup">Share on Facebook</a>
<a href="http://www.twitter.com/intent/tweet?url=URL_HERE&via=TWITTER_HANDLE_HERE&text=TITLE_HERE" target="_blank" class="share-popup">Share on Twitter</a>
<a href="http://plus.google.com/share?url=URL_HERE" target="_blank" class="share-popup">Share on Googleplus</a>
Because they contain the share-popup
class, we can easily reference these in jQuery, and change the window size to suit the domain we are sharing from:
$(".share-popup").click(function(){ var window_size = "width=585,height=511"; var url = this.href; var domain = url.split("/")[2]; switch(domain) { case "www.facebook.com": window_size = "width=585,height=368"; break; case "www.twitter.com": window_size = "width=585,height=261"; break; case "plus.google.com": window_size = "width=517,height=511"; break; } window.open(url, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,' + window_size); return false; });
No more ugly inline JavaScript, or countless window sizing alterations. And it still supports non-JavaScript users.