facebook弹出窗口阻止Feed共享

时间:2012-09-03 12:02:17

标签: facebook

我有以下功能,用户可以共享Feed。以下代码在大多数浏览器上被弹出窗口阻止程序阻止。关于这个问题我已经看过几篇关于堆栈溢出的帖子。一个推荐使用我试过的onclick。我注意到,如果我的facebook sdk失败,我不会得到弹出窗口块。什么是最好的攻击计划。我正在使用php。

<a class="facebook" href="#" onclick='loadSdk(); return false;'></a>

<script>

function loadSdk(){

    window.fbAsyncInit = function() {
        FB.init({
            appId      : '123', // App ID
            channelUrl : 'http://mysite.com/facebook', // Channel File
            //   status     : true, // check login status
            cookie     : true, // enable cookies to allow the server to access the session
            xfbml      : true  // parse XFBML

        });

        if (typeof facebookInit == 'function') {
            facebookInit();
        }

        FB.api('/me', function(user) {
            if (user) {
                var image = document.getElementById('image');
                image.src = 'https://graph.facebook.com/' + user.id + '/picture';
                var name = document.getElementById('name');
                name.innerHTML = user.name
            }
        });
    };
    // Load the SDK Asynchronously
    (function(d){
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) {return;}
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);

    }(document));
}

 function facebookInit(){

        var publish = {
            method: 'feed',
            message: '',
            name: '',
            caption: '',
            description: (

                ),
            link: 'http://mysite.com/',
            picture: 'http://mysite.com/fblogo.png',
            actions: [
                { name: '123', link: 'http://www.mysite.com/' }
            ],
            user_message_prompt: 'Share your thoughts'
        };

        FB.ui(publish, null);

}

</script>

1 个答案:

答案 0 :(得分:1)

目前您正在加载SDK onclick - 为什么?

你想在你的情况下执行打开弹出窗口的函数 - facebookInit - onclick。