如何使用新的 Facebook JavaScript SDK 关闭(隐藏)FBML 对话框?
我今天浪费了四个小时和几根头发试图解决这个问题但失败了。
我们使用 facebook.connect 来授权我们网站上的用户并执行各种操作。这些操作之一应该触发 fbml:dialog
,我决定使用新的 JavaScript SDK。这是我使用的功能:
function popupModalWindow(cat) {
var oldSize = FB.UIServer.Methods["fbml.dialog"].size;
FB.UIServer.Methods["fbml.dialog"].size = {width: 402, height: 112};
//FB.UIServer.id = FB.UIServer._active[id];
var messages = {
interesting: '<p>By submitting my entry, I confirm that I have obtained permission from the persons whose picture and/or voice appears in my entry for use and publication in this contest as outlined in the Official Rules [link]</p>'
};
// alert(messages[cat]);
FB.ui(
{
method: 'fbml.dialog',
//id: 'ololo',
display: 'dialog',
width: 402,
height: 112, /**/ //Should work that way according to the API reference
size : {width: 402, height: 112},
fbml: '<link rel="stylesheet" href="http://rentatext.mygrate.biz/styles.css"/><div class="modal-white" style="width: 402px;">'+
'<h6>User Agreement</h6>'+
'<fb:js-string var="oloe">document.getElementsByTagName("iframe")[0].id;</fb:js-string>'+
'<div class="inner">'+messages[cat]+' <a class="fb-close" onclick="FB.UIServer._active[oloe].close()">i agree</a></div></div>'
,
},
function() {
alert(1);
}
);
console.debug(FB.UIServer);
}
不幸的是,设计者将这些模态窗口制作为灰色背景,一些用户可能没有注意到对话框右上角的默认“关闭”按钮。我需要的是将事件绑定到某个将关闭此对话框的自定义元素。我尝试过不同的方法,但没有一个有效。
当我使用 onclick 事件处理程序单击 a.fb-close
时,最新的抛出“a138033292903816_FB 未定义”。也许我错过了一些东西,我用谷歌搜索了很多,但没有运气。
I've wasted four hours today and several hairs trying to solve this issue but failed.
We use facebook.connect
to authorize users on our site and perform various actions. One of these actions should trigger fbml:dialog
, I decided to use new JavaScript SDK. Here's the function I use:
function popupModalWindow(cat) {
var oldSize = FB.UIServer.Methods["fbml.dialog"].size;
FB.UIServer.Methods["fbml.dialog"].size = {width: 402, height: 112};
//FB.UIServer.id = FB.UIServer._active[id];
var messages = {
interesting: '<p>By submitting my entry, I confirm that I have obtained permission from the persons whose picture and/or voice appears in my entry for use and publication in this contest as outlined in the Official Rules [link]</p>'
};
// alert(messages[cat]);
FB.ui(
{
method: 'fbml.dialog',
//id: 'ololo',
display: 'dialog',
width: 402,
height: 112, /**/ //Should work that way according to the API reference
size : {width: 402, height: 112},
fbml: '<link rel="stylesheet" href="http://rentatext.mygrate.biz/styles.css"/><div class="modal-white" style="width: 402px;">'+
'<h6>User Agreement</h6>'+
'<fb:js-string var="oloe">document.getElementsByTagName("iframe")[0].id;</fb:js-string>'+
'<div class="inner">'+messages[cat]+' <a class="fb-close" onclick="FB.UIServer._active[oloe].close()">i agree</a></div></div>'
,
},
function() {
alert(1);
}
);
console.debug(FB.UIServer);
}
Unfortunately, the designer made these modal windows with grey background and some users may not notice the default "close" button at the top right corner of dialog. What I need is to bind an event to some custom element that will close this dialog. I've tried different approaches but none of them worked.
The latest one throws "a138033292903816_FB is not defined" when I click a.fb-close
with the onclick event handler. Maybe I'm missing something, I googled a lot but with no luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也有同样的麻烦。第二天寻找解决方案。刚刚找到一种方法:
要关闭活动 FB 对话框,您应该在 FB JS 可用且调用 FB.ui 的父窗口中执行以下代码:
因此,在您的情况下 - 请尝试在 iframe 中使用此 JS:
希望这有帮助
I have same trouble. Second day looking for a solution. And just found one way:
for closing active FB dialog you should perform followed code in parent window where FB JS is available and where FB.ui was called:
So, in your case - please try use this JS in iframe:
Hope this help
Facebook 将所有 JavaScript 函数和变量重命名为随机字符串。 看看这个。也许您可以使用 CSS 来更改模式的背景?
Facebook renames all of your javascript functions and variables to a randomstring. Check out this. Maybe you could use CSS to change the modal's background?