如何使用新的 Facebook JavaScript SDK 关闭(隐藏)FBML 对话框?

发布于 2024-09-13 16:35:44 字数 1797 浏览 4 评论 0原文

我今天浪费了四个小时和几根头发试图解决这个问题但失败了。

我们使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青巷忧颜 2024-09-20 16:35:44

我也有同样的麻烦。第二天寻找解决方案。刚刚找到一种方法:
要关闭活动 FB 对话框,您应该在 FB JS 可用且调用 FB.ui 的父窗口中执行以下代码:

FB.Dialog.remove(FB.Dialog._active);

因此,在您的情况下 - 请尝试在 iframe 中使用此 JS:

parent.FB.Dialog.remove(parent.FB.Dialog._active);

希望这有帮助

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:

FB.Dialog.remove(FB.Dialog._active);

So, in your case - please try use this JS in iframe:

parent.FB.Dialog.remove(parent.FB.Dialog._active);

Hope this help

混吃等死 2024-09-20 16:35:44

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文