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?

  • Cannot the FireFox addon periodically ping the site to verify if the login has been successful, after the login pop-up has been shown?
    – avpaderno
    Commented Jun 1, 2011 at 4:29
  • @kiamlaluno, yes that's what I meant with "polling the login-state". But shouldn't there be a better way? btw why did you edit my question?
    – modoq
    Commented Jun 1, 2011 at 6:35
  • Are you asking why I removed the part I removed, or are you asking why I edited your question, without any reference to what I removed/changed?
    – avpaderno
    Commented Jun 1, 2011 at 6:40
  • @kiamlaluno Never mind. I agree with your changes. Was just surprised someone cares about my question ;-) Thanks anyway.
    – modoq
    Commented Jun 1, 2011 at 7:49
  • I do care of any question. :-)
    – avpaderno
    Commented Jun 1, 2011 at 8:08

1 Answer 1


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(&$form, &$form_state) {
  $form['#submit'][] = 'mymodule_login_submit';

function mymodule_login_submit($form, &$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() {
    ->fields(array('weight' => 10))
    ->condition('name', 'mymodule')
  • I'm sorry I don't follow you Ok, this is where I would tell my popup to close. But window.close() won't work here either, will it?
    – modoq
    Commented Jun 1, 2011 at 8:45
  • If I'd set a JS variable in an extra form submission handler, how would that help me to close my popup and tell my ff-extension to procede?
    – modoq
    Commented Jun 1, 2011 at 8:55
  • I expanded my answer.
    – avpaderno
    Commented Jun 1, 2011 at 8:55
  • @modoq If you set a JavaScript variable in the form submission handler, that would not change the value of the JavaScript variables loaded in the popup window; it would change the content of JavaScript variable in the next page loaded in the main window.
    – avpaderno
    Commented Jun 1, 2011 at 9:02
  • @kiamlaluno Are you suggesting, that pinging a Drupal JavaScript variable is better than polling the login session directly? (Is ping and poll the same thing?)
    – modoq
    Commented Jun 1, 2011 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.