Showing popup in the new Facebook JavaScript SDK

前端 未结 9 1482
遥遥无期
遥遥无期 2020-12-30 17:15

I used to have an href in my website. When users clicked on it, a multi-friend selector showed so they could invite their friends to my website. That was done u

相关标签:
9条回答
  • 2020-12-30 17:27

    I just do this. FB.ui({ method: 'fbml.dialog', width: 500, height: 300, fbml:......

    0 讨论(0)
  • 2020-12-30 17:30

    Yes, finally got the irritating box to resize from the original 964 pixels:

    For compatibility (let's hope it will get fixed in the future, or documented better) I still say

    size:(width:600,height:500),
    

    but then I break out width and height as properties of parent object, so in the end use:

    size:(width:600,height:500),width:600,height:500, ...
    

    And now it's also resizable with the JavaScript library of your choice, that is, here's a sample with jQuery resizing:

    FB.ui({
        method: 'fbml.dialog',
        fbml: (
             '<div style="width:480px;border:1px black solid;">A small JavaScript library that allows you to harness ' +
             'the power of Facebook, bringing the user\'s identity, ' +
             'social graph and distribution power to your site.</div>'
           ),
        size: {width:640,height:480}, width:640, height:480
    });
    $(".FB_UI_Dialog").css('width', $(window).width()*0.8); // 80% of window width
    // I'm also sure you could stack this call if you wanted to
    
    0 讨论(0)
  • 2020-12-30 17:36

    The following code works for me, but please note the following:

    • The width and height refer to the dialog-box itself, WITHOUT the "faded" thick blue border.
    • The width + height appear in the following code in 3 places.
    • The COLS and ROWS attribute match the size in the following example - 625x515 pixels.
    • Since IE sucks, I had to use jQuery with $.browser to force a POP-UP in IE.

    Hope this helps :)

    function fb_invite_friends() {
        FB.ui({method:'fbml.dialog', display:($.browser.msie ? 'popup' : 'dialog'), size:{width:625,height:515}, width:625, height:515, fbml:'<fb:request-form action="http://yoursite.com/" method="POST" invite="true" type="DayBox" content="Would you like to check out YOUR-SITE App too? <fb:req-choice url=\'http://apps.facebook.com/your-site/\' label=\'Yes\' />" <fb:multi-friend-selector showborder="false" actiontext="Invite your friends to use DayBox" cols=5 rows=3 bypass="cancel" email_invite="true" import_external_friends="false" /> </fb:request-form>'});
    }
    
    $(document).ready(function() {
    
        /* Facebook */
        window.fbAsyncInit = function() {
            FB.init({appId: fb_app_id, status: true, cookie: true, xfbml: true});
            if (facebook_canvas) {
                FB.Canvas.setAutoResize(4000); // Will resize the iFrame every 4000ms
            }
            FB.Event.subscribe('edge.create', function(response) {
                // The user clicked "LIKE", so we give him more coins!
                $.get(href_url, {action:'log_likes'});
            });
            // FBML Dialog size fix
            FB.UIServer.Methods["fbml.dialog"].size = {width:625, height:515};
        };
        (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);
        }());
    
    }
    
    0 讨论(0)
  • 2020-12-30 17:40

    None of the previous answers were working for me. The workaround I found was to do the following:

    var uiSize = FB.UIServer.Methods["fbml.dialog"].size;
    FB.UIServer.Methods["fbml.dialog"].size = {width:760, height:450};
    
    FB.ui({
        method:'fbml.dialog',
        display: 'popup',                   
        fbml: message
    },
        function( response ){
            FB.UIServer.Methods["fbml.dialog"].size = uiSize;
        }
    );
    
    0 讨论(0)
  • 2020-12-30 17:40

    Just in case that someone need help with application request and friend invitation here is facebook docs about that: http://developers.facebook.com/docs/reference/dialogs/requests/ and piece of code that you need is:

    FB.ui({method: 'apprequests', message: 'A request especially for one person.', data: 'tracking information for the user'});
    
    0 讨论(0)
  • 2020-12-30 17:43

    Well, after 2 days (because I'm not a JavaScript expert :P ) of reading the open source Facebook JavaScript SDK, I found a method:

    FB.ui({
                method : 'fbml.dialog',
                fbml: '<fb:fbml>' +
                      '<fb:request-form action=......',
            });
    

    It looks simple, yes I know, but now the problem is when I send the invitation, I get a new tab opened leaving the "dialog" (in Facebook terms, because popup means another thing for them!!) open!

    So I am still struggeling, but I will find the answer!

    0 讨论(0)
提交回复
热议问题