Skip to content

Instantly share code, notes, and snippets.

@corbanb
Created October 14, 2014 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corbanb/c431f92397e0617a6330 to your computer and use it in GitHub Desktop.
Save corbanb/c431f92397e0617a6330 to your computer and use it in GitHub Desktop.
Facebook and Twitter Custom Shares
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
</head>
<body>
<!-- Twitter Docs - https://dev.twitter.com/web/intents#tweet-intent -->
<a href="https://twitter.com/intent/tweet?url=http://mywebsite.com&via=corbanb&text=Custom copy for the tweet"></a>
<!-- Facebook Docs - https://developers.facebook.com/docs/sharing/reference/feed-dialog/v2.1 -->
<div class="fb-share-button"></div>
<script>
// INIT FACEBOOK APP
window.fbAsyncInit = function() {
FB.init({
appId : 'your-app-id',
xfbml : true
version : 'v2.1'
});
// ADD CLICK HANDLER
$('.fb-share-button').click(function(){
<!-- Facebook Docs - https://developers.facebook.com/docs/sharing/reference/feed-dialog/v2.1 -->
FB.ui({
'method': 'feed',
'description': 'My Custom Share Copy'
'href': 'http://mywebsite.com',
'picture': 'http://mywebsite.com/custom_share_image.jpg'
}, function(response){});
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<script type="text/javascript" async src="//platform.twitter.com/widgets.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment