本文介绍了用户单击类似Facebook的按钮后重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带iframe应用程序的facebook标签,在该标签中有一个facebook like按钮,它具有第二个功能来喜欢facebook页面.这是一个普通的Facebook,例如按钮iframe.
I have a facebook tab with an iframe application and within that tab there is a facebook like button to have a second capability to like the facebook page. It is an ordinary facebook like button iframe.
单击按钮时是否可以重定向用户?我尝试了以下代码:
Is there a possibility to redirect the user when it clicks the button? I tried it the following code:
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: '<my app id>', status: true, cookie: true, xfbml: true});
FB.Canvas.setSize({ width: 520, height: 1500 });
FB.Event.subscribe('edge.create',
function(response) {
alert('like!');
}
);
};
//Load the SDK asynchronously
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
但这不起作用.有办法还是我做错了什么?
But this doesn't work. Is there a way or am I doing something wrong?
推荐答案
我刚刚测试了以下代码,它可以按预期工作
I just tested the following code and it works as expected
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head></head>
<body>
<div id="fb-root"></div>
<fb:like href="http://yoururlto.like" send="false" width="450" show_faces="false" font=""></fb:like>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: 'YOUR_APP_ID', status: true, cookie: true, xfbml: true});
FB.Canvas.setSize({ width: 520, height: 1500 });
FB.Event.subscribe('edge.create',
function(response) {
alert('like!');
// put redirect code here eg
window.location = "http://www.mysite.com/redirected.html";
}
);
};
//Load the SDK asynchronously
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
</body>
</html>
它与您自己的页面相比如何?
How does it compare to your own page?
这篇关于用户单击类似Facebook的按钮后重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!