使用display = popup进行Facebook Connect登录,如何让弹出窗口关闭,父级刷新?

时间:2011-09-14 00:31:55

标签: facebook

我已经阅读了大量的线程,试图解决关于Facebook登录系统的“如何关闭弹出窗口以及刷新父窗口”的问题。我已经尝试了所有的东西,但因为有很多方法可以实现FB登录,所以我似乎无法使用我正在使用的方式。这是我的代码:

include('./includes/facebook.php');

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => 'MYAPPID(SET)',
  'secret' => 'MYSECRET(ALSOSET)'
));

// Get User ID
$user = $facebook->getUser();

// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

// Login or logout url will be needed depending on current user state.
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl(array('display' => 'popup','next' => 'index.php', 'cancel_url' => 'index.php'));
}

该代码在文档的html开始解析之前运行。然后我稍后加载一下:

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
  FB.init({
    appId  : 'MYAPPIDSTILLHERE',
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    xfbml  : true, // parse XFBML
    channelURL : './channel.html', // channel.html file
    oauth  : true // enable OAuth 2.0
  });
</script>

然后,我的登录链接(如果用户尚未登录):

<a href="#" onclick="popup('<?php echo $loginUrl; ?>')" title="Login with Facebook"><img src="http://static.ak.fbcdn.net/rsrc.php/v1/y6/r/kGCxkZx-uZa.gif" /></a>

popup()函数已定义,弹出窗口本身效果很好,但是当您输入登录信息时,弹出窗口会刷新,并且您会在一个小弹出窗口中登录我的网站。如何让它关闭并刷新打开弹出窗口的窗口?

0 个答案:

没有答案