Focus caret automatically at www.example.com/?q=user

Last modified: August 26, 2009 - 23:55

This php snippet will automatically give focus to the username field when anonymous users visit www.example.com/?q=user.

The snippet should be inserted immediately before the <?php print $closure;?> tag in your page.tpl.php.

<?php

// If user is not logged in and visits user page,
// focus caret on username text input.
if ((arg(0) == "user") && (!$user->uid)) {
print
"[script type=\"text/javascript\"]\n";
print
"document.getElementById('edit-name').focus()\n";
print
"[/script]\n";
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.