Hello,
I want to have web visitors use the FACEBOOK LIKE script to like my webpage and redirect them to a specific URL after they like the page. Is this possible?
Thanks,
Troy
Hello,
I want to have web visitors use the FACEBOOK LIKE script to like my webpage and redirect them to a specific URL after they like the page. Is this possible?
Thanks,
Troy
Hey Troy,
The JavaScript API let’s you like something and then respond.
FB.api(
"/me/og.likes",
"POST",
{
"object": "http:\/\/samples.ogp.me\/226075010839791"
},
function (response) {
if (response && !response.error) {
/* handle the result */
window.location = 'other-page.html';
}
}
);
https://developers.facebook.com/docs/reference/opengraph/action-type/og.likes
Hi Mark,
Would this go in the header of the web page that contains the Facebook Page Like code?
Thanks,
Troy
An easier way to do this is to subscribe to the event edge.create for likes on the page.
Here’s a complete example.
<html>
<head>
<title>Your Website Title</title>
<!-- You can use open graph tags to customize link previews.
Learn more: https://developers.facebook.com/docs/sharing/webmasters -->
<meta property="og:url" content="http://www.your-domain.com/your-page.html" />
<meta property="og:type" content="website" />
<meta property="og:title" content="Your Website Title" />
<meta property="og:description" content="Your description" />
<meta property="og:image" content="http://www.your-domain.com/path/image.jpg" />
</head>
<body>
<!-- Load Facebook SDK for JavaScript -->
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'your-app-id',
xfbml : true,
version : 'v2.5'
});
FB.Event.subscribe('edge.create',
function(response) {
alert('You liked the URL: ' + response);
}
);
FB.Event.subscribe('edge.remove',
function(response) {
alert('You UNliked the URL: ' + 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>
<!-- Your like button code -->
<div class="fb-like"
data-href="http://www.your-domain.com/your-page.html"
data-layout="standard"
data-action="like"
data-show-faces="true">
</div>
</body>
</html>
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.