我有一个Facebook模态对话框,我想将其放置在自定义模态对话框中(作为html元素)。这是我到目前为止的内容:
对于Facebook对话框:
$(document).ready(function(){
window.fbAsyncInit = function () {
FB.init({ appId: '***************', cookie: true, xfbml: true, oauth: true });
// *** here is my code ***
if (typeof facebookInit == 'function') {
facebookInit();
}
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
function facebookInit() {
FB.ui({
url : 'http://www.google.com',
method: 'feed',
name: 'The name',
link: 'crowd.com',
caption: 'An example caption',
}, function (response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
});
}
});
对于模式:
<div id="myModal1new" class="modal1 hide welcome-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
</div>
<div class="modal-header"></div>
<div class="modal-body">
<div id="fb-root"></div>
</div>
无论如何,我可以将两者结合起来(将FB对话框放置在自定义模式中)吗?也许使用各种iframe?先感谢您。
最佳答案
坏消息是您无法做到的,facebooks具有共享的所有URL,例如sharer.php
和按URL的feed对话框,如下所示:
https://www.facebook.com/dialog/feed?
app_id=145634995501895
&display=page&caption=An%20example%20caption
&link=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fdialogs%2F
&redirect_uri=https://developers.facebook.com/tools/explorer
不会在iframe中进行渲染,因为Facebook会阻止所有内容在一个iframe中进行渲染。这是您尝试使用Facebook内容创建iframe时引发的错误:
Refused to display 'https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.google.com' in a frame because it set 'X-Frame-Options' to 'DENY'.
由于您无法使用iframe,并且每次Feed对话框都会打开一个新窗口,因此您可以完成类似操作的唯一方法是创建自己的“共享对话框”,但是请记住,要做到这一点,您必须向用户询问权限代表他们发帖。