diff -rNB -U 3 .\fboauth.install ..\fboauth_d6_new\fboauth.install
--- .\fboauth.install	Sat May 05 20:57:04 2012
+++ ..\fboauth_d6_new\fboauth.install	Wed Dec 12 11:52:39 2012
@@ -23,6 +23,7 @@
   drupal_uninstall_schema('fboauth');
   variable_del('fboauth_id');
   variable_del('fboauth_secret');
+  variable_del('fboauth_popup_connect');
   variable_del('fboauth_user_email');
   variable_del('fboauth_user_username');
   variable_del('fboauth_user_picture');
diff -rNB -U 3 .\fboauth.module ..\fboauth_d6_new\fboauth.module
--- .\fboauth.module	Sat May 05 20:57:04 2012
+++ ..\fboauth_d6_new\fboauth.module	Wed Dec 12 12:01:31 2012
@@ -1,9 +1,26 @@
 <?php
 
+function fboauth_init() {
+   drupal_add_js(drupal_get_path('module','fboauth') . '/fboauth_popup.js');
+}
+
 /**
  * Implements hook_menu().
  */
 function fboauth_menu() {
+  $items['fboauth/connect'] = array(
+      'title' => 'Facebook connect process',
+      'page callback' => 'fboauth_connect',
+      'access callback' => TRUE,
+      'type' => MENU_CALLBACK,
+  );
+  $items['fboauth/popup/connect'] = array(
+      'title' => 'Facebook connect popup',
+      'page callback' => 'fboauth_popup_connect',
+      'access callback' => TRUE,
+      'type' => MENU_CALLBACK,
+  );
+
   $items['fboauth/%fboauth_action'] = array(
     'title' => 'Facebook connect',
     'page callback' => 'fboauth_action_page',
@@ -39,6 +56,29 @@
   return $items;
 }
 
+function fboauth_connect() {
+  // modify uri to point to the relocated menu path of fboauth
+  if (variable_get("fboauth_popup_connect")) {
+    $url = str_replace("connect","popup/connect",$_SERVER['REQUEST_URI']);
+    // output some javascript to close the popup window and redirect the parent Drupal window
+    echo "<script>";
+    if (! isset($_REQUEST['error'])) {
+      echo "window.opener.location='$url';";
+    }
+    echo "setTimeout(function(){ window.close(); }, 500);
+      </script>";
+  }
+  else {
+      module_load_include('inc','fboauth','includes/fboauth.fboauth');
+      return fboauth_action_page(array("name" => "connect"));
+  } 
+  
+}
+function fboauth_popup_connect() {
+  module_load_include('inc','fboauth','includes/fboauth.fboauth');
+  return fboauth_action_page(array("name" => "connect"));
+}
+
 /**
  * Implements hook_theme().
  */
@@ -350,6 +390,9 @@
     ),
     'href' => 'https://www.facebook.com/dialog/oauth',
   );
+  if (variable_get("fboauth_popup_connect",0)) {
+     $return['attributes']['class'] = 'facebook-action-connect facebook-action-popup-connect';
+  }
 
   if ($permissions) {
     $return['query']['scope'] = implode(',', $permissions);
diff -rNB -U 3 .\fboauth_popup.js ..\fboauth_d6_new\fboauth_popup.js
--- .\fboauth_popup.js	Thu Jan 01 01:00:00 1970
+++ ..\fboauth_d6_new\fboauth_popup.js	Wed Dec 12 12:00:45 2012
@@ -0,0 +1,44 @@
+/**
+ * add Drupal behaviors
+ */
+Drupal.behaviors.fboauth_popup = function(context) {
+  
+  /**
+   * modify Facbook Oauth (fboauth) button with class "facebook-action-connect" to open in a popup window, instead
+   * of using the current window.
+   * References:
+   * http://thinkdiff.net/facebook/create-facebook-popup-authentication-window-using-php-and-javascript/
+   * http://developers.facebook.com/docs/authentication/
+   * http://developers.facebook.com/docs/authentication/server-side/
+   * http://developers.facebook.com/docs/reference/dialogs/oauth/
+   */
+  $('.facebook-action-popup-connect').click(function() {
+    var screenX    = typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft,
+      screenY    = typeof window.screenY != 'undefined' ? window.screenY : window.screenTop,
+      outerWidth = typeof window.outerWidth != 'undefined' ? window.outerWidth : document.body.clientWidth,
+      outerHeight = typeof window.outerHeight != 'undefined' ? window.outerHeight : (document.body.clientHeight - 22),
+      width    = 500,
+      height   = 270,
+      left     = parseInt(screenX + ((outerWidth - width) / 2), 10),
+      top      = parseInt(screenY + ((outerHeight - height) / 2.5), 10),
+      features = (
+        'width=' + width
+        + ',height=' + height
+        + ',left=' + left
+        + ',top=' + top 
+      );
+    // The second parameter should not contain spaces or IE shows javascript error. But other browser will not complain.
+    // So here, we use “Login_by_facebook” and not “Login by facebook”.
+    var title = "Login_by_Facebook";
+    var url = $(this).attr("href"); 
+
+    // use 'popup' mode, so that the OAuth dialog is displayed in a form suitable for embedding in a popup window.
+    newwindow = window.open(url+"&display=popup", title, features);
+    if (window.focus) {
+      newwindow.focus();
+    }
+    // don't follow href from anchor tag to prohibit facebook login to open in drupal window
+    return false;
+  });
+}	
+
diff -rNB -U 3 .\includes\fboauth.pages.inc ..\fboauth_d6_new\includes\fboauth.pages.inc
--- .\includes\fboauth.pages.inc	Sat May 05 20:57:04 2012
+++ ..\fboauth_d6_new\includes\fboauth.pages.inc	Wed Dec 12 11:53:51 2012
@@ -27,6 +27,14 @@
     '#description' => t('To use Facebook connect, a Facebook Application must be created. Set up your app in <a href="http://www.facebook.com/developers/apps.php">my apps</a> on Facebook.') . ' ' . t('Enter your App Secret here.'),
     '#default_value' => variable_get('fboauth_secret', ''),
   );
+  $form['fboauth_popup_connect'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Show Facebook login in popup'),
+    '#description' => t('Show Facebook login in popup'),
+    '#options' => array(0 => t("No"), 1 => t("Yes")),
+    '#default_value' => variable_get('fboauth_popup_connect', 0),
+  );
+
 
   $form['fboauth_basic_mapping'] = array(
     '#type' => 'fieldset',
@@ -137,6 +145,7 @@
 function fboauth_settings_form_submit($form, &$form_state) {
   variable_set('fboauth_id', $form_state['values']['fboauth_id']);
   variable_set('fboauth_secret', $form_state['values']['fboauth_secret']);
+  variable_set('fboauth_popup_connect', $form_state['values']['fboauth_popup_connect']);
 
   variable_set('fboauth_user_email', $form_state['values']['fboauth_user_email']);
   variable_set('fboauth_user_username', $form_state['values']['fboauth_user_username']);
