0

I'm trying to add:

drupal_add_js('jQuery(document).ready(function () { jQuery("input#edit-name").focus(); });', 'inline');

to the user login page when the user is not logged in. This lack of login form focus is one of my worst web annoyances.

What would be the most efficient way to do this?

I can add the code to every page by adding it to my theme's js, but this is inefficient.

In the theme's template.php I can use theme_preprocess_page() and check for $variables['logged_in'] but how do I test for only the /user page?

1 Answer 1

1

You can use the drupal_match_path() function:

$path = drupal_get_path_alias();
$pattern = 'user';

    if (drupal_match_path($path, $pattern)) {
      drupal_add_js('jQuery(document).ready(function () { jQuery("input#edit-name").focus(); });', 'inline');
    }
1
  • I just found I could use arg(0) == 'user' Is either method preferable and why?
    – Naidim
    Sep 5, 2013 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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