Skip to content

Instantly share code, notes, and snippets.

@keeganstreet
Created May 12, 2011 12:43
Show Gist options
  • Save keeganstreet/968422 to your computer and use it in GitHub Desktop.
Save keeganstreet/968422 to your computer and use it in GitHub Desktop.
Facebook share links

You can create feed dialogues on Facebook simply by navigating to a URL. You don't need to include the hefty Facebook JavaScript SDK (unless you need post published callbacks).

Here's a demo with some JavaScript that will open the dialogue as a popup window at the correct size. If the popup is blocked, it will fall back to a target="_blank".

The feed properties are documented here: http://developers.facebook.com/docs/reference/dialogs/feed/

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>These Days</title>
<meta name="author" content="These Days">
<style>
p { font-family: sans-serif; color: #666; }
</style>
</head>
<body>
<p>You can now close this window.</p>
</body>
</html>
<?php
echo '<a href="https://www.facebook.com/dialog/feed?app_id='.FB_APP_ID.
'&redirect_uri='.urlencode(APP_URL.'/close.html').
'&display=popup'.
'&link='.urlencode('http://labs.thesedays.com').
'&picture='.urlencode('http://fbrell.com/f8.jpg').
'&name='.urlencode('These Days').
'&caption='.urlencode('Hello there').
'&description='.urlencode('Bla bla bla bla bla bla. Two sentences is a good description.').
'&message='.urlencode('Its so easy!').
'" target="_blank" class="facebookShare">Post to Facebook</a>';
$(".facebookShare").click(function(e) {
var win = window.open($(this).attr("href"), "Facebook", "height=400,width=580");
if (window.focus) {
win.focus();
}
if (win) {
e.preventDefault();
}
});
<?php
// Alternatively, if you'd just like to share a page, you can simply include a link to the Facebook sharer URL.
echo '<a href="http://www.facebook.com/sharer/sharer.php?u='.urlencode(APP_URL).'" target="_blank">Share on Facebook</a>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment