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

3

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

我们使用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未定义”的错误。也许我漏了什么东西,我已经搜索了很多但没有找到解决方法。
2个回答

2

我有同样的困扰。第二天一直在寻找解决方案。最终找到了一种方法: 要关闭活动的FB对话框,您应该在调用FB.ui的父窗口中执行以下代码:

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

因此,在您的情况下,请尝试在iframe中使用此JS:
parent.FB.Dialog.remove(parent.FB.Dialog._active);
希望这有所帮助。

0

Facebook会将您的所有JavaScript函数和变量重命名为随机字符串。看看这个。也许您可以使用CSS来更改模态框的背景?


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接