How to close login-popup after successful login I'm working on a FF-extension, that displays user-specific information on 3rd-party websites. Users need to be logged in to my Drupal-website. I'm checking login state with a cross-domain-proof jQuery.ajax(). If a user is not logged in, the FF-extension opens a popup-window (window.open()) showing a Drupal login/register/passwordlost page (/user/login).

Now I would like this window to close and the FF-extension to carry on, as soon as the login (registration/password-request) is successful. And now I'm lost. How would I do this?

I know how to close the popup from my FF-addon (window.close()), but I don't know how to tell the addon, when to do it. I thought of polling the login-state. But that seems kind of clumsy, no? I have also tried redirecting the drupal-page after successful login (login destination module) to a self-closing page, but in newer browsers window.close() works only on windows, that were created with the same script. And then I would still have to find a way to tell the FF-addon to proceed.

How do other people solve this?
The user login form is the one returned from user_login(), or user_login_block(). In both the cases, user_login_submit() is the form submission handler that is invoked for the login form.

Adding a form submission handler that is executed after user_login_submit() would be possible to set a Drupal variable.

function mymodule_form_user_login_form(&amp;$form, &amp;$form_state) {
  $form['#submit'][] = 'mymodule_login_submit';
}

function mymodule_login_submit($form, &amp;$form_state) {
  global $user;

  variable_set('mymodule_user_logged_in', (integer) !empty($user));
}


The addon could then periodically ping a URL handled from the module, which would return the value of "mymodule_user_logged_in," and close the window when its value is not 0.
The code I wrote here is not optimized, and it serves only as example of what is possible to do.

To allow to the added form submission handler to be called after the submission handler added by user.module, the weight of the module should be changed to a value that is different from the default module weight, in hook_install() or hook_update_N().

function mymodule_install() {
  db_update('system')
    -&gt;fields(array('weight' =&gt; 10))
    -&gt;condition('name', 'mymodule')
    -&gt;execute();
}