Facebook登录无法在Safari / iPhone上打开

5

我正在创建一个显示Facebook好友的应用程序。首先,用户需要点击登录按钮,然后会出现一个简单的弹出屏幕,在填写登录ID和密码后,它将显示好友列表。
一切都很正常,在Firefox、Chrome和IE上运行得很好,但在Safari和iPhone上无法打开弹出窗口。
有人建议我在channelUrl中添加域名和频道名称。我创建了一个channel.html并添加了引用,但没有帮助我。
我搜索了很多,但没有找到有用的信息。

这是我的代码。
Custom.js

function getUser()
{
FB.init({
    appId      : '289403314507596', // App ID
    channelUrl : 'http://bc2-236-161.compute-1.amazonaws.com/html/channel.html', // Channel File
    status     : true, // check login status
    cookie     : true, // enable cookies to allow the server to access the session
    xfbml      : true  // parse XFBML
});

 (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));

//check current user login status
FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
        window.location="facebook_friend.html"
        loadFriends();
    } else {
        //user is not connected.
        FB.login(function(response) {
            if (response.authResponse) {
                window.location="facebook_friend.html"
                loadFriends();
            } else {
                alert('User cancelled login or did not fully authorize.');
            }
        });
    }
 });
 }
//start from here
 $(document).ready(function(){
$('.load-button').click(function(){
    getUser();
});
});   

channel.html

<script src="//connect.facebook.net/en_US/all.js"></script>// i add this line in channel.html

refer_friend.html
我在这个文件里添加了custom.js的引用

 <div id="fb-root"></div>
   <script src="http://connect.facebook.net/en_US/all.js"></script>
   <img src="includes/fb-btn1.png" class="load-button" style="
    width: 290px;
    Height: 40px;
    margin-top: 5px;"/>
1个回答

5

好的...在浪费了整整一天之后,我终于得到了答案。使用 Javascript_Facebook Sdk,当你点击登录按钮时,它会打开弹出窗口。而在Safari或iPhone(我的手机)上启用了阻止弹出选项。
因此,我无法看到Facebook登录窗口。你需要允许弹出窗口。
你可以通过点击来允许弹出窗口

Safari-disable Block pop-up windows  

或者
 safari-preference-then disable checkbox of pop-up window's    

或者您可以使用键盘快捷键:
shift-[command key]-K.

干杯。


4
你的代码主要问题是自动调用了 FB.login,这样弹出窗口很可能会被当前浏览器阻止。通常建议只在显式用户交互(例如点击链接/按钮触发登录)时调用此方法。 - CBroe
Safari似乎非常敏感。如果在上面的代码中调用FB.getLoginStatus,同样会发生这种情况。目前在Safari版本6.0.5(7536.30.1)中遇到了这个问题。我认为这是因为即使由用户点击事件触发/调用,FB.login也是在函数内部调用的缘故... - Björn
在我的情况下,我把它放在了一个点击处理程序中,但它仍然没有打开。问题是页面的布局将按钮隐藏在屏幕之外,直到发生其他用户交互为止。这就是为什么Safari的安全设置阻止了弹出窗口。因此,请确保您有一个可见的按钮来触发弹出窗口。 - user967451

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