[英]How can I add a redirect for after my Facebook page is liked?
i have a web site which has some Facebook like buttons like below 我有一个网站,上面有一些类似Facebook的按钮,如下所示
<div class="like-box">
<div class="fb-like" data-href="https://www.facebook.com/samebirthday.officialpage" data-width="500" data-layout="box_count" data-action="like" data-show-faces="true" data-share="false"></div>
</div>
<div id="fb-root"></div>
<script>
//facebook
(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/ja_JP/all.js#xfbml=1&appId=700721206653864";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
and then, how can I add a redirect for after my Facebook page is liked? 然后,如何在我的Facebook页面被赞后添加重定向? i tried this one, but it didn't work. 我尝试了这个,但是没有用。
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '700721206653864',
status : false, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true // parse XFBML tags on this page?
});
FB.Event.subscribe('edge.create',
function(response) {
alert('liked!');
}
);
FB.Event.subscribe('edge.remove',
function(response) {
alert('unliked!');
}
);
};
</script>
<script src='http://connect.facebook.net/ja_JP/all.js'></script>
Use the subscribe event of as edge.create, this is the event fired when someone likes the page using a Like button. 使用as edge.create的订阅事件,这是当有人使用“喜欢”按钮喜欢页面时触发的事件。 Add a redirect to it: 添加重定向到它:
FB.Event.subscribe('edge.create',
function(response) {
window.location.href = 'http://the_URL_you_want';
}
);
You need to add an EventListener on the and add it to the chain! 您需要在上添加一个EventListener并将其添加到链中!
` `
var flike = document.getElementById('-------'); var flike = document.getElementById('-------');
flike.addEventListener('click', function(){ flike.addEventListener('click',function(){
// here you can do the redirection //在这里您可以进行重定向
}, false); },错误); ` `
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.